Hooked up ESP to Nano = fail, but can i hook Nano to ESP?

my project needs 4 analogue inputs (2 x MQ-2 & 2 x MQ-7 gas sensors) but this wont work with my ESP8266-12E board.

so naively i hooked up an ESP8266-12 as a shield for a Nano and got it working (learned some AT commands, yay!), but then i tried to upload my code (that i had originally written for my ESP8266) but now it says the code is too big for the Nano! how rude!!!

so instead? can i run the ESP with the main code and digital sensors connected, and have a Nano hanging off it (like a shield?) with only the code relating to the analogue sensors and sending this to the ESPā€™s Tx/Rx connections?

is there an example i could look at?

1 Like

@Dave1829 see example 3 here.

Then incorporating Blynk:
Sending device:

  ESPserial.write("<");  // start marker
  ESPserial.write(outstr);  // e.g "23.7"
  ESPserial.write(">");   // end marker

Receiving device:

  tempC = atof(receivedChars);   // array to float conversion
  Blynk.virtualWrite(V1, tempC);  // writes 23.7 to Blynk Value Display

In the receiving device you need to call void recvWithStartEndMarkers() and showNewData() with SimpleTimer.

2 Likes

1 Like

Thanks Costas!! i will see how far i can get before it return with more questionsā€¦

and pfft!! no wires!!! how does it all work??? does your magic smoke has some place to travel? :wink:

1 Like

@Dave1829 the connections are all on the underside of the circuit board.

it is an interesting idea - replace functions arduino and esp8266.
ESP as a wifi connection with the installed BLYNK and arduino as an extension ports for ESP. Both connected by serial hardware.
Very interesting - I have to check it in practice
Thank you for the idea

Iā€™ve got somewhere a small piece of code that allows to read analog inputs or write digital outputs using serial com on demand. This code with @Costas link could work togetherā€¦ I will share it with you

iā€™m pretty close!!

here is my Nano sketch:

#define debug 1 // this is the debugging tag - change to 0 to turn off debugging  serial prints

#include <SimpleTimer.h>
#include "Wire.h"

const int fireRoomSmokePin = A1; //SMOKE GAS sensor output pin for upstairs plenum MQ-2 sensor
const int fireRoomCO2Pin = A2; //CO GAS sensor output pin for upstairs plenum MQ-7 sensor

int fireRoomSmoke;
//int fireRoomCO2;
SimpleTimer timer;
#include "SoftwareSerial.h"
SoftwareSerial EspSerial(2, 3); // RX, TX

void runGasSensorTest()
{
#ifdef debug
  Serial.println(F("Starting to read gas sensors...."));
#endif
  fireRoomSmoke = analogRead(fireRoomSmokePin); //Read Gas value from analog 1

  EspSerial.write("<");  // start marker
  EspSerial.write(fireRoomSmoke);  // variable to send
  EspSerial.write(">");   // end marker
  
#ifdef debug
  Serial.println(F("smoke sensor reading:"));
  Serial.println(fireRoomSmoke);
#endif
  //  fireRoomCO2 = analogRead(fireRoomCO2Pin); //Read Gas value from analog 2
  //  EspSerial.write("<");  // start marker
  //  EspSerial.write(fireRoomCO2);  // variable to send
  //  EspSerial.write(">");   // end marker
  //#ifdef debug
  //  Serial.println(F("carbon monoxide sensor reading:"));
  //  Serial.println(fireRoomCO2);
  //#endif
}

void setup()
{
  //Serial.begin(115200);
  Serial.println(F(""));
  Serial.println(F("FIRE ROOM ENVIRO MONITOR - Gas sensor sending"));
  Serial.print(F("File name: "));
  Serial.println(__FILE__);

  Serial.begin(9600);
  delay(10);

  EspSerial.begin(9600);
  delay(10);

  timer.setInterval(6L * 1000L, runGasSensorTest);
  Serial.println(F("SimpleTimer begins runGasSensorTest() at 6 second intervals..."));
}

void loop()
{
  timer.run(); // Initiates SimpleTimer
}

and here is my ESP8266 sketch:


#define DEBUG 1 // this is the debugging tag - change to 0 to turn off debugging  serial prints
#define BLYNK_PRINT Serial //this is the debugging for Blynk
//#define BLYNK_DEBUG        // Optional, this enables 'full' debugging with detailed prints
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include "Wire.h"
#include <TimeLib.h>

//this is the stuff for espserial receive from Nano
const byte numChars = 32;
char fireRoomSmoke[numChars];
char fireRoomCO2[numChars];
boolean newData = false;
int dataNumber = 0;     
float fireRoomSmokeC;
//end nano stuff

WiFiClient client;

const char* ssid = "eyeHeartBlynk";
const char* password = "CostasRulz";

char authBlynk[] = "numberletternumbernumberletteretcetc"; //insert token generated by Blynk

SimpleTimer timer;

void sendGasSensorReadings()
{
  fireRoomSmokeC = atof(fireRoomSmoke);   // array to float conversion
  Blynk.virtualWrite(V7, fireRoomSmokeC);
}

void recvWithStartEndMarkersSmoke() {
  static boolean recvInProgress = false;
  static byte ndx = 0;
  char startMarker = '<';
  char endMarker = '>';
  char rc;

  while (Serial.available() > 0 && newData == false) {
    rc = Serial.read();

    if (recvInProgress == true)
    {
      if (rc != endMarker)
      {
        fireRoomSmoke[ndx] = rc;
        ndx++;
        if (ndx >= numChars)
        {
          ndx = numChars - 1;
        }
      }
      else
      {
        fireRoomSmoke[ndx] = '\0'; // terminate the string
        recvInProgress = false;
        ndx = 0;
        newData = true;
      }
    }
    else if (rc == startMarker)
    {
      recvInProgress = true;
    }
  }
}

void showNewData() {
  if (newData == true) {
    Serial.print(F("This just in ... "));
    Serial.println(fireRoomSmoke);
    newData = false;
  }
  else {
    Serial.println(F("nothing from Nano yet................ ... "));
  }
}

void setup()
{
  Serial.begin(9600);

  Blynk.begin(authBlynk, ssid, password);

  while (!Blynk.connect())
  {
    //Wait until connected
    delay(50);
    Serial.print(F(". "));
  }

  Serial.println(F(""));
  Serial.println(F("Found some WiFi!"));
  long rssi = WiFi.RSSI();
  Serial.print(F("WiFi signal strength (RSSI): "));
  Serial.print(rssi);
  Serial.println(F(" dBm"));
  Serial.println("");
  Serial.println(F("------------"));

  bool isFirstConnect = true; // Keep this flag not to re-sync on every reconnection

  BLYNK_CONNECTED(); // This function will run every time Blynk initial connection is established
  {
    if (isFirstConnect) {
      Blynk.syncAll(); // where is the sync.All function supposed to go?
      isFirstConnect = false;
    }
  }

  Serial.println(F("Blynk syncAll done! We operate under <SimpleTimer.h> now:"));

  timer.setInterval(70L * 1000L, sendGasSensorReadings);
  Serial.println(F("SimpleTimer begins sendGasSensorReadings() at 70 second intervals..."));
  timer.setInterval(25L * 1000L, recvWithStartEndMarkersSmoke);
  Serial.println(F("SimpleTimer begins recvWithStartEndMarkers() at 25 sec intervals..."));
  timer.setInterval(26L * 1000L, showNewData);
  Serial.println(F("SimpleTimer begins showNewData() at 26 sec  intervals..."));
}

void loop()
{
  Blynk.run(); // Initiates Blynk
  timer.run(); // Initiates SimpleTimer
}

and this is my output:

> [5001] Connecting to blynk-cloud.com:8442
> [5695] Ready (ping: 0ms).

> Found some WiFi!
> WiFi signal strength (RSSI): -40 dBm

> ------------
> Blynk syncAll done! We operate under <SimpleTimer.h> now:
> SimpleTimer begins sendGasSensorReadings() at 70 second intervals...
> SimpleTimer begins recvWithStartEndMarkers() at 25 sec intervals...
> SimpleTimer begins showNewData() at 26 sec  intervals...
> This just in ... /
> This just in ... ƶ
> This just in ... e
> This just in ... n
> This just in ... ĀŖ
> This just in ... y
> This just in ... {
> This just in ... Ć·
> This just in ... "
> This just in ... A
> This just in ... Ā½

the sensor is an analogue MQ2 gas module, and puts out 0 to 999 i think,

like this:

Starting to read gas sensors....
smoke sensor reading:
978
Starting to read gas sensors....
smoke sensor reading:
523
Starting to read gas sensors....
smoke sensor reading:
480
Starting to read gas sensors....
smoke sensor reading:
819
Starting to read gas sensors....
smoke sensor reading:
201
Starting to read gas sensors....
smoke sensor reading:
726
Starting to read gas sensors....
smoke sensor reading:
637
Starting to read gas sensors....
smoke sensor reading:
162
Starting to read gas sensors....
smoke sensor reading:
530
Starting to read gas sensors....
smoke sensor reading:
824
Starting to read gas sensors....
smoke sensor reading:
395
Starting to read gas sensors....
smoke sensor reading:
224
Starting to read gas sensors....
smoke sensor reading:
742
Starting to read gas sensors....
smoke sensor reading:
894
Starting to read gas sensors....
smoke sensor reading:
443
Starting to read gas sensors....
smoke sensor reading:
260
Starting to read gas sensors....
smoke sensor reading:
924
Starting to read gas sensors....
smoke sensor reading:
880

so i know i have messed my variable types up somewhere, but not sure whereā€¦?

is it where it ESPwrite it in the Nano? or where it process it in the ESP8266?

@Dave1829 yes the ESPwrite line of:

EspSerial.write(fireRoomSmoke); // variable to send

needs to be something like:

float floatfireRoomSmoke = fireRoomSmoke / 1.0;
String stringfireRoomSmoke;
dtostrf(floatfireRoomSmoke,5, 1, stringfireRoomSmoke;);
EspSerial.write(stringfireRoomSmoke);  // variable to send
1 Like

@Dave1829,
I know that you are pointing at other direction, but, as you said you need 4 analog inputs the ADS1115 came to my mind. Itā€™s a 16-Bit ADC - 4 Channel with Programmable Gain Amplifier. The ADS1115 provides 16-bit precision at 860 samples/second over I2C.

You can see more details here:

And a better price below:

http://es.aliexpress.com/item/ADS1115-ADC-ultra-compact-16-precision-ADC-module-development-board/32294613634.html?spm=2114.13010608.0.52.z4cHPZ

Regards!!!

so i tried that, bout could not get it to work so after a bit of hacking (as i knew it was close) i got to this one:

  char msgBuffer[10];
  char *sendFireRoomSmoke;
  float floatfireRoomSmoke = fireRoomSmoke / 1.0;
  sendFireRoomSmoke = dtostrf(floatfireRoomSmoke, 5, 1, msgBuffer);

and it works enough for my purposesā€¦

it DOES change the raw numbers from 200 to 800 range to figures between 80 and 130 range - but it is a relative reading, not absolute, so itā€™s fineā€¦

@Dave1829 relative or not that canā€™t be right.

What data type are the original figures of 200 to 800 and how many decimal places?

I think you might need to change the 5, 1.
In my actual project I check how many digits there are in the number and also if it is plus or minus (temperature) and alter the 5 ,1 accordingly.

The type of data? It is a positive integer i think? No decimal places. Possibly over 1000 but not sureā€¦

If it is 1000 to 9999 then the integer has 4 characters.
When it becomes a float by dividing by 1.0 it becomes 6 characters (4 plus 2 for .x).
So

sendFireRoomSmoke = dtostrf(floatfireRoomSmoke, 5, 1, msgBuffer);

would need to be:

sendFireRoomSmoke = dtostrf(floatfireRoomSmoke, 6, 1, msgBuffer);

The other way to do all this is with division, modulus and adding ā€˜0ā€™ to each digit which converts them to characters before you send them to the ESP.

Hi Costas

Can you please show me wiring of arduino and wemos?

Hi @NHN,

I thought it would be easier to open up one of our boxes to look at the pin connections rather than look in the two corresponding sketches.

I was rather shocked when I opened the box that I thought was shown in post 2 of this thread. Rather than a WeMos and a Nano all sitting neatly with barely a wire in sight it was a mass of wires and an ESP07 with a Nano. I think my business partner currently has the nice neat one.

Anyway you can pretty much use any pins you like. You define an rx and tx in the SoftwareSerial of the Arduino. You then need to ensure you put a voltage divider between the Arduino tx pin and the rx of the ESP.

I have just looked at the 2 sketches and for the Nano I have this line:

SoftwareSerial ESPserial(8, 7); // RX | TX [ONLY PIN 7 TX REALLY NEEDED ON NANO]

I can confirm on the box I have opened I only have pin 7 on the Nano connected to the ESP (via a voltage divider). Basically what this is saying is that as I was just sending from Nano to ESP then you only need the TX line from the Arduino connected to the RX line of ESP (via a voltage divider).

A couple of notes in the ESP sketch:

// ENSURE COMMON GROUND FROM NANO TO ESP
#include <SoftwareSerial.h>
// ONLY D5 RX IS NEEDED ON ESP, FROM PIN 7 (TX) OF NANO
// USE NANO GND NEAR RST PIN AND VITAL A VOLTAGE DIVIDER IS USED
SoftwareSerial ESPserial(14, 13); //RX and TX D5 and D7 WeMos, TX not connected

HTH

I made my nodemcu work with Uno, success connect to Blynk. I connect directly Unoā€™s TX RX to RX TX of nodeMCU, donā€™t use voltage divider. After flashed right AT firmware, it worked. You know how to use AT firmware with GPIO pin of esp-12? Searched from Espressif forum, but nothing talk about that

thks

At least we will all know why your system suddenly stops working.
I know the basics of the AT command set as I was using them 30+ years ago but I wouldnā€™t recommend anyone uses them with an ESP when there are much better ways to do it.

1 Like

@Dave1829,
I have been playing with the ADS1115 doing a small Shield for the Wemos Mini D1, it works like a charm!
Itā€™s really easy to use with Blynk and you can achieve 4 extra analog inputs.

See below:

And the video:

Hope you like it!

Kind regards

2 Likes

@psoro could we have a link to your supplier for the ADS1115, thanks.

The ADS1115 takes 2 digital pins. Any reason you couldnā€™t have 2 off attached to the WeMos to provide 8 analogue ports?

Edit: One of my WeMos ā€œbuddiesā€ has pointed out that the ADS1115 is an i2s device so 2 boards would only require 2 digital pins, not 4.