Sending data from UNO with ESP8266

Hi,

I built a project with an Arduino UNO. It’s controling a device
and monitoring 4 different sensors and it’s working well.

Now I need to send the data sensors to an iPhone so in order to
monitor my device remotely.

I need a 200 or 300 feets away range so Bluetooth is not good.

ESP8266

I would like to use an ESP8266 as a Wi-Fi transmitter to send the
data from/to my Arduino UNO.

It can be sent to IO.Adafruit but I don’t know how.

I found a lot of examples on the net but it involve the ESP8266 alone
with the sensors connected directly to the ESP8266.

That’s not good because my project is already working with the UNO.
So I need a way to do that using the ESP8266 as a wi-fi transmitter.

one option is GitHub - bportaluri/WiFiEsp: Arduino WiFi library for ESP8266 modules

hddforensic:
I found a lot of examples on the net but it involve the ESP8266 alone
with the sensors connected directly to the ESP8266.

Use one of those examples and just send the data from the Arduino to the ESP using serial.

Lennyz1988:
Use one of those examples and just send the data from the Arduino to the ESP using serial.

but then he must maintain two sketches. switching boards in IDE, which then does a complete recompile etc. and when he decides to use Ethernet ...

Juraj:
but then he must maintain two sketches. switching boards in IDE, which then does a complet recompile etc. and when he decides to use Ethernet ...

Yes your method is more efficient but in case that's to difficult for him, then you can also try my suggestion.

Do you mean that I will have to create a sketch for the ESP8266 alone so it will take the data from
my existing Arduino project and send it to where I want like IO.adafruit ?

hddforensic:
Do you mean that I will have to create a sketch for the ESP8266 alone so it will take the data from
my existing Arduino project and send it to where I want like IO.adafruit ?

Yes. This way, the ESP handles all network-related stuff (HTTP etc.) and you can make abstraction of it in your Arduino code, just read the sensor values and send them to the Serial port, it doesn't have to worry about anything else.

Using AT commands would be possible as well, but I personally prefer this method.

Pieter

you could connect the sensor to ESP and you don’t need the Uno. porting the sketch should be easy

Hi Juraj,

I think there is not enough pins to connect all my sensors and buttons directly to the ESP8266.

4 buttons
4 relays output
1 analog sensors to A1
2 ADS1115 for 2 sensors
2 LCD display
LCD display and ADS1115 take the same pins (4,5) but I need 8 pins for buttons and relays
and I will probably need to add one button and one relay soon.

IMG_9463.JPG

I understand. You know, that if you connect ESP8266 to Serial, you can't use Serial for usb?

I use Uno Wifi witch is an Uno board with ESP8266 as 'coprocessor' or 'slave' processor. There is a firmware from the manufacturer in the ESP8266 and a corresponding library on the atmel side.
The good and the bad thing is that the ESP is not connected to serial on Uno Wifi. I can use usb serial monitor without affecting the communication with the ESP. The bad thing is that the connection to ESP is slow.

Hardware is easier than coding for me since I never did any code before but
electronic yes.

I saw a few good examples of IOT at Adafruit with the ESP8266 alone but ESP8266 alone
doesn't have enough pins to handle my 4 push button and 4 relays.

Is it possible to expand the ESP8266 with more pins with an i2c board of some sort ?

Also, is the ESP8266 fast as the UNO ?

I'm starting to think that it will be more easy for me to change my UNO for a king size EDP8266 :slight_smile:
and then add to my code the code example for MQTT and Adafruit IO dashboard.

hddforensic:
Is it possible to expand the ESP8266 with more pins with an i2c board of some sort ?

You could use I²C port expanders, or you could drive your relays using shift registers (many outputs using only 3 microcontroller outputs).

hddforensic:
Also, is the ESP8266 fast as the UNO ?

The ESP8266 is many times faster (80-160MHz compared to the UNO's 16MHz) and it has many times more RAM (64 KiB of instruction RAM, 96 KiB of data RAM compared to 2KiB on the UNO). Most ESP8266 dev boards (e.g. WeMos D1 mini, NodeMCU, ...) have 4MB of flash, of which you can use up to 3MB for data storage (for web pages, data logging, ...)

Pieter

ESP8266 has 11 digital and 1 analog pins.
Port extenders can take care of the extra pin requirements.
Or if you like more pins and even more processing power there's the ESP32.

wvmarle:
Or if you like more pins and even more processing power there's the ESP32.

The ESP32 Arduino Core is not yet on the same level as the ESP8266 Core, it misses some great features like built-in web server libraries etc. There are also fewer examples and information online.
For now, I prefer to use the ESP-IDF, Espressif's official development framework. It has quite a steep learning curve if you're not familiar with C programming and RTOS-specific design patterns, but it's definitely doable, especially if you follow Neil Kolban's great book: Kolban's book on ESP32 by Neil Kolban [Leanpub PDF/iPad/Kindle]

Pieter

Hi Wvmarle,

11 digital and 1 analog pins is almost ok for me, too bad that 2 digital are used for the i2c.

I have no choice but to find a way to expand the pins.

Do you have a part number for a port extender ?

https://playground.arduino.cc/Code/I2CPortExpander8574

Port expanders can be used as inputs or outputs, most have pin change interrupts.
Serial in - parallel out shift registers can only be used as outputs, but are really fast (SPI speed).
Parallel in - serial out shift registers can only be used as inputs, and are really fast as well (SPI speed). You need to latch the data in, though, so you don't have get a pin change interrupt, you have to poll.

Pieter

PCF8574 (a simple, rather old but also dirt cheap one) or the MCP23008 give you 8 extra digital ports, the MCP23017 gives you 16 extra digital ports.
ADS1115 is an inexpensive choice for 4-port analog input expander, or if the 10-bit resolution is simply not enough.

hddforensic:
Hi Wvmarle,

11 digital and 1 analog pins is almost ok for me, too bad that 2 digital are used for the i2c.

I have no choice but to find a way to expand the pins.

Do you have a part number for a port extender ?

Why not make it simple and just use softwareserial to send the data to an esp8266. You can use an esp8266-01 or maybe a wemos d1 mini.

If your goal is to use the Adafruit MQTT library then prepare for some headache. Its a terribly slow and blocking a library. The standard pubsubclient library is unable to connect to the Adafruit MQTT library.

It's also my current problem because it seems to me that I can't get full AVR like functionality out of an ESP8266 with the Arduino core. I wanted to use an OLED display, but trying to compile the Adafruit library (the only one that I know of that will run the display) using the ESP core was a train wreck. It looked like PROGMEM was a problem. I don't mind changing things in my programs but I hate fiddling with libraries too much. Also I want to use 5V for a lot of peripherals. So I argue that it makes sense at least some of the time to use the ESP as a serial add-on using the AT commands. But I'm finding out that there isn't a lot of material out there that I can draw on.

Hi wvmarle,

In my project, I have two ads1115 and 5 of the analog pins are not use.

Can I use them for buttons ? If yes can you give me an example on
how I have to say in the code to use it as a button.

Right now in my code for the Arduino I say:

int pinButton1 = A1;
int RELAY1 = 3;
int stateRELAY1 = LOW;
int stateButton1;

So If I want to use the pin no 1 on one of my ads1115 named "ads_02",
how do I need to do it ?

Unless it's easier to used them as output for the relay.