Croduino Basic and ESP8266 serial communication for sensor data

Customer:

I have a Croduino Basic that reads sensor data (for example temperature) and outputs it to serial and LCD. I want to store this data in a MySQL database. I know PHP and MySQL, but I’m stuck on how to make the Croduino Basic and ESP8266 communicate with each other.

I need the sensors to stay connected to the Croduino because I plan to add more sensors. How can the Croduino send data through a pin to the ESP8266 and have the ESP8266 receive it? What code needs to go on the Croduino and what on the ESP8266?

Original message (Croatian)

Kupio sam kod vas CroduinoBasic.

Naime pokušavam napraviti jedan projekat ali zapeo sam na jednom detalju.

Bez problema Croduino ucitava podatke s senzora (recimo temperatura) i izlistava mi ih na serial i na LCD, tocno kako sam i htio.

Htio bih te informacije spremati u MySQL bazu podataka. PHP i MySQL mi nisu problem, znam taj dio, no muci me kako da napravim da CroduinoBasic i ESP8266 komuniciraju?

Želim da je senzor i dalje uštekan u Croduino pošto planiram dodati jos neke senzore, te iz tog razloga mi treba Croduino.

I kako da on recimo preko nekoga pina šalje podatke u ESP8266 a ESP da ih prima?

Što je potrebno da napravim u Croduinu a što u ESP? Napominjem da sve ostalo sto ima veze s GET metodom, PHP i mysql mi nije problem.

hvala

Originally submitted via email support on 7 January 2017. Migrated to the forum for community visibility.

Soldered Support:

Communication between two Arduino boards can be done in several ways: serial (UART), I2C, or parallel (SPI). Serial is probably the simplest, while I2C is the most efficient.

Here’s an example for I2C communication: I2C Between Arduinos : 5 Steps (with Pictures) - Instructables

Original message (Croatian)

pretpostavljam da programirate ESP8266 iz Arduina. Ono što Vam treba u tom slučaju je komunikacija između dva Arduina. (Ali zašto ne spojite odmah senzor direktno na ESP8266? Nema dovoljno pinova verzija koju koristite?)
Komunikacija između dvije Arduino pločice se može odraditi na više načina: serijski(UART), I2C ili paralelno(SPI). Najjednostavnije je vjerojatno serijski, a najefikasnije putem I2C komunikacije.
Evo primjer za I2C komunikaciju: I2C Between Arduinos : 5 Steps (with Pictures) - Instructables

Customer:

I can program the ESP8266 by switching it to flash mode and selecting “Generic ESP8266” in the Arduino IDE, and switch to the Arduino board when needed.

The ESP8266 doesn’t have enough pins for my project. It can connect to WiFi as a client and work as a webserver, but I need to transfer output from the Arduino to it.

Here’s the code on the Arduino:

void loop()
{
 int val;
 int chk = DHT.read11(DHT11_PIN);
 val = DHT.temperature;
 delay(1000);
 Serial.print("Temperature: ");
 Serial.println(val);
}

This sends temperature to serial, which I can read on the COM port. But I want to send that number to the ESP8266 so it can send it to the database or display it on a webserver.

I’m confused about which code goes on the ESP and which on the Arduino, and how to arrange the pins so TX and RX are correct. I’ve seen tutorials where TX connects to TX and RX to RX, and others where RX connects to TX. I just need guidance on which direction to look.

Original message (Croatian)

Da, kada nešto radim na ESP-u, samo ga prebacim u flash mode, i u ArduinoIDE za board izaberem “Generic ESP8266”, a kada želim nešto staviti na Arduino onda samo izaberem Arduino plocicu iz izbornika.

ESP8266 mi nema dovoljno pinova za projekat koji radim:

https://cdn.sparkfun.com//assets/parts/1/1/1/2/9/13678-01.jpg

[https://cdn.sparkfun.com//assets/parts/1/1/1/2/9/13678-01.jpg]

Uspio sam spojiti ESP8266 na svoju wifi mrezu i da bude client, i da radi kao webserver i sve to super radi.

Problem mi je samo kako da na njega prebacim output s Arduina.

Ovo je dio koda:

void loop()

{

int val;

int chk = DHT.read11(DHT11_PIN);

val = DHT.temperature;

delay(1000);

Serial.print("Temperature: ");

Serial.println(val);

}

Prakticki to samo salje temperaturu na serial, i bez problema je mogu procitati kada otvorim COM port gdje mi je plocica na USB-u.

Ali taj broj želim prebaciti na ESP8266 i da ga on onda dalje šalje u bazu ili ga prikazuje na webserver no to nije problem, to je laksi dio posla :slight_smile:

Zbunjuje me to malo koji dio koda moram staviti na ESP, koji na Arduino?

I kako pinove da poslozim da bude ispravno TX i RX, jel na dosta tutoriala sam vidio da negdje treba TX na TX, RX na RX, a negdje RX na TX.

Ne treba mi netko da mi završi projket do kraja, samo neka usmjernica da znam u kojem pravcu da gledam :slight_smile:

Hvala puno!

Soldered Support:

When connecting two devices serially, you connect TX to RX and RX to TX (crossed over). Everything else you’ve written is correct and should work.

Original message (Croatian)

Nisam još shvatio koja je uloga Arduina u cijeloj priči, dakle, zašto ESP ne odrađuje cijeli kod?
U svakom slučaju, pri serijskom spajanju dva uređaja spajate TX na RX te RX na TX (dakle unakrsno).
Ovo sve ostalo što ste napisali je točno i trebalo bi funkcionirati. Javite ako sam gdje falio i treba još pomoći :slight_smile:

Customer:

The ESP8266 isn’t sufficient in this case because I have several sensors, not just one. I need at least 3 sensors. Does anyone have an example sketch that performs this type of communication over TX and RX ports?

Original message (Croatian)

ESP8266 mi nije dovoljan u ovom slucaju pošto imam nekoliko senzora, a ne samo jedan.

Bilo bi minimalno 3 senzora, te s toga.

Ima neki primjer sketcha koji obavlja takvu vrstu komunikacije preko TX i RX portova?

(ne trebamo na Vi, kud smo iz istog mjesta, a i godinama smo blizu :slight_smile: )

Soldered Support:

There are ESP8266 versions with more pins available, for example:

Here’s an example of how to connect an ESP8266 and Arduino: https://cdn.instructables.com/FC5/FW5J/IGHOIQAH/FC5FW5JIGHOIQAH.LARGE.jpg

Voltage dividers are needed because the ESP8266 requires 3.3V signals on the serial port.

Now you can communicate between two boards using the Serial library. What one board does with Serial.print(), the other can read with Serial.read() when Serial.available() != 0.

Original message (Croatian)

Inače imaš verzije ESP-a s više pinova, recimo:

Soldered: Open-Source Electronics, Boards, Sensors & Modules – Soldered Electronics

Soldered: Open-Source Electronics, Boards, Sensors & Modules – Soldered Electronics
Ovo je npr. način povezivanja ESP8266 i Arduina: https://cdn.instructables.com/FC5/FW5J/IGHOIQAH/FC5FW5JIGHOIQAH.LARGE.jpg

Voltage divideri su jer ESP8266 treba 3.3V signale na serijskom portu.
Sada možeš komunicirati između dvije pločice putem Serial library-a. Što jedna pločica Serial.print(), druga može Serial.read() kada je Serial.available() != 0.
Nadam se da je sve ovo jasno što sam napisao :slight_smile:

Customer:

I saw those boards with more pins! But for now I want to get this working with the Arduino, and this is exactly what I was looking for: Serial.print and Serial.read. The Arduino does Serial.print and the other does Serial.read. Everything is clear now.

I’ll test it out and report back. Just one small thing: I’ve uploaded sketches directly to the ESP8266 a few times, and now it won’t respond to AT commands anymore. Is that normal?

Original message (Croatian)

Vidio sam te plocice s više pinova!

Ali trenutno zelim napraviti da mi to ovako radi preko Arduina, i vjeruj mi ovo je tocno sto sam trazio:

serial.print i serial.read

Arduino da radi serial.print, a ovaj drugi da radi serial.read.

Sve je kristalno jasno naravno.

Probat cu se malo igrati pa javim kako je proslo. Samo jedna sitnica još, nekoliko puta sam stavio sketch direktno na ESP8266, i sada mi više ne odgovara na AT komande? To je normalno?

Naravno ove informacije sto si mi dosad dao i pomogao ne ocekujem besplatno, tako da kada odradim tu komunikaciju među karticama dogovorimo se.

Soldered Support:

Serial communication can be tricky at first because you need to be careful with the Serial buffer and read all the data in time before it overflows. But yes, that’s the way to do it!

I’m not entirely sure why the ESP doesn’t respond to AT commands anymore. I think it happens because you replace the original bootloader with the Arduino bootloader, but I’m not 100% sure. To be safe: do you have a good connection, correct baud rate, and are you adding \n\r at the end of each message? What’s the combination of GPIO 0, 2, and 15 pin states (according to this page: https://zoetrope.io/tech-blog/esp8266-bootloader-modes-and-gpio-state-startup)? Probably flash mode?

Original message (Croatian)

Može bi imalo nezgodno s serijskom komunikacijom u početku jer treba paziti na Serial buffer i čitati sve info na vrijeme, prije nego se on oveflowa.. Ali da, to je to!
Iskreno, nisam siguran zašto ESP više ne reagira na AT komande. Mislim da treba tako biti jer originalni bootloader zamijeniš Arduinovim, ali nisam 100% siguran. Za svaki slučaj: sigurno imaš dobru konekciju, dobar baud i dodaješ \n\r na kraj svake poruke? Koja je kombinacija GPIO 0, 2 i 15 pinova(prema ovoj stranici: https://zoetrope.io/tech-blog/esp8266-bootloader-modes-and-gpio-state-startup)? Vjerojatno flash?
Ne brini za plaćanje, tu sam da pomognem :slight_smile: