Trying to bitbang i2c oled screen, using SSD1306Ascii library
I have an irrigation node with 6 analog soil sensors.
Now I want to attach an I2C OLED screen, and drive it with the SSD1306Ascii library.
The problem is the screen uses SDA and CLK which are analog pins 3 and 4.
Ideally I don't want to give up two soil sensors to add the screen.
- Can I use bigbang I2C on the binary pins while still using the SSD1306Ascii library?
- Or will software I2C use so much memory that all this will never work?
- Should I buy another screen? Is there a version with (software) serial control?
Google hasn't been very helpful
@alowhum seems simple enough? https://playground.arduino.cc/Main/SoftwareI2CLibrary
very lightweight (roughly 250 bytes of flash and 0 byte of RAM, except for call stack)
on the other hand, the SSD1306Ascii library seems unable to support software i2c.
https://github.com/greiman/SSD1306Ascii/blob/master/src/utility/AvrI2c.h assumes hardware i2c
@mfalkvidd Yes, that's what I ran into too.
Screens that can be controlled through software serial might be an option. So far though it seems that most Aliexpress shops call I2C screens "serial"..
Hi @alowhum why using the SPI variant?
This will require only one digital IO pen for the chip select (CS pin) the rest is shared with the radio SPI interface (MOSI, MISO, SCK, CE and power off course)
I don't quite follow. Do you mean I should use the SPI version of the screen?
Since I am using NRF24 as a radio I thought that might not be possible, since it already occupies the Arduino Nano's SPI interface?
Another idea might be to connect all analog sensors to I2C Analog-digital converters like the ADS1115:
As you can hook up multiple devices to the same i2c bus, simply attach the OLED and two of those ADS1115 boards (apparently you can assign up to 7 different I2C addresses to the ADC boards...) to the I2C bus.
If you insist on connecting the analog sensors to the arduino and switch to a software I2C implementation on non-hardware I2C pins, you might simply extend the SSD1306Ascii library. It currently has classes for the SSD1306 over the AVR hardware i2c, another class for generic Wire implementations (not tailored to atmel chips; e.g. I'm using it on nrf51822), and the SPI devices.
Looking at the SoftwareI2CLibrary docs, it appears that they even provide a Wire interface (SoftWire.h), so you might even get away with the SSD1306AsciiWire class for the OLED.
If that does not work, you'll have to write your own software I2C implementation for the SSD1306Ascii class (e.g. takt SSD1306AsciiWire, rename it to SSD1306AsciiSoftI2C and adjust it to use the SoftwareI2C library for all I2C communication).)
@alowhum SPI is a shared bus. Many devices can use it. Which device is active is controlled by the CS pin.
Thanks everyone. That's a lot to think about.
This looks interesting: a completely serial screen for $4:
For anyone finding this: I got that 'smart' LCD screen that can be controlled with serial commands. It's awesome!
The screen now displays a bar graph for all 6 moisture sensors (irrigation controller).