28.08.2019»»среда

Software Serial Esp8266 I2c

28.08.2019
    0 - Comments
Software Serial Esp8266 I2c Rating: 10,0/10 7592 reviews

A program to set instructions and get information from an SPS30. It has been tested to run either UART or I2C communcation on ESP32, MEGA2560, ESP8266 and UNO. A detailed description of the options and findings are in SPS30.odt As part of a larger project I am looking at analyzing and understanding.

Based on the Espruino Design notes , I have pullups:

  • ESP8266 with 20×4 i2c, 1602 LCD adaptable to others. I2C is a serial protocol for two-wire interface to connect low-speed devices like microcontrollers, EEPROMs, A/D and D/A converters, I/O interfaces and other similar peripherals in embedded systems. It was invented by Philips and now it is used by almost all major IC.
  • Choice of 'matching' baudrate (e.g 9600, 57600, 115200) for 2 sets of serial comms: ESP8266Arduino, and ArduinoUSB serial monitor (hardware serial or software serial). Choice of 5v and 3.3v bridging circuitry between Arduino and ESP8266. Choice of Arduino Mega or Uno, that affect the availability of serial.

I2C Implementation

The I2C interface is implemented in software because the esp8266 does not have hardware support for i2c (contrary to what the datasheet seems to imply). The software implementation has the following limitations: it operates at approx 100Khz, it is master-only, and it does not support clock stretching (a method by which slaves can slow down the master). The I2C interface can be bound to almost any I/O pin pair, but you should avoid gpio15 because it needs to be pulled-down at boot time and the I2C bus needs pull-up resistors. The pins chosen for I2C are configured to be open-drain outputs and an external pull-up resistor is required on each of the two pins. Remember that esp8266 pins are not 5v compatible...

Based on Thorsten's advice from gitter, I've tried GPIO12/13:

Based on this wii nunchuck blog I'm using 3.3V

Not sure what else to try.
Should I be using an arduino as an I2C to serial adapter?
Seems a pity if this functionality is available on the ESP8266 espruino builds, no?

Active2 years, 8 months ago

I am doing a task that send sensor data Through WIFI from esp to PC application to visualize it. all parts of this project done except the one that send the sensor data from UNO to ESP on software serial.

Wiring:

  • connect Rx (0) of UNO to pin (12) in ESP. as Tx

  • connect Tx (1) of UNO to voltage divider to take 3.3 v to ESP. pin (14) as Rx.

  • ground of ESP. to Ground of UNO.
  • V+ of ESP. to 3v3 of UNO.

Code:

Esp8266 I2c Pins

Attached two codes to test this process if it is working or not. One on ESP and another on arduino

After building I found according to the screenshow below, there is something being send because of the condition of while loop and the delay I set but the output is converted to numbers not string, random numbers !

Software Serial Esp8266 I2cduskwuff
157k22 gold badges194 silver badges246 bronze badges
Serial
ahmadebahmadeb

1 Answer

  • V+ of ESP. to 3v3 of UNO.

The 3v3 pin on a standard Uno will not supply enough current for an ESP8266 to work reliably.

Serial on the Uno is connected to Arduino pins 0 and 1, which you're using for output to the Serial Monitor on your computer(as well as uploading sketches). You're also using pins 0 and 1 to communicate with the ESP8266 using software serial. You can't use the same pins for both these purposes at the same time. You need to either use different pins for your software serial or, since you're currently not doing anything useful with Serial you could switch to using Serial on the Uno to communicate with the ESP8266 and remove the software serial code.

If you're going to continue to use software serial on the Uno then you should use a lower baud rate than 115200 as the Arduino SoftwareSerial library is not reliable at that speed.

I don't know what you think this code is doing:

but it's definitely not going to work.

The line:

is the equivalent of:

Maybe you meant to use a char array:

However that will not be compatible with

So you would either need to change it to:

which will print the full string at once, or you could work through the array one character at a time:

The line:

checks if there is incoming data available from the ESP8266 but that's never going to be true because you don't ever send any data from the ESP8266 over software serial. If it ever did receive any data then it would get permanently stuck in that while loop because you never read the received data. Then instead of reading that non-existent incoming data you write the number 16 to the ESP8266:

I recommend you take the time to read the documentation for the Arduino SoftwareSerial library. The same information should also apply to the ESP8266 SoftwareSerial library you're using on the ESP8266.

per1234per1234
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.

Not the answer you're looking for? Browse other questions tagged arduinoesp8266 or ask your own question.