Hi. I'm posting in general electronics as I think the following might cause something the Arduino detects as a short circuit, making it crash:
I have 6 analog 10k B potentiometers connected to my Arduino Uno. The left contacts connect to 5V, the wipers connect to the digital inputs (A0 to A5) and the right contacts go to ground.
I can read the signal of all 6 potentiometers simultaneously with the Arduino and print them to serial.
Now, I disconnect the potentiometers and try out only my 0.91inch 128x32 OLED display which I use with the u8g2 library.
That works without problems, showing a "hello world" test message or anything I want.
However, when I have the display connected, the Arduino crashes and the display doesn't show anything anymore or it doesn't show the previous message correctly, as soon as I connect more than 4 of my potentiometers to the analog inputs even if I don't implement them in the code yet. It doesn't matter which analog inputs I use and I have also tried two other Arduino Uno boards to make sure it's not broken.
Could it be that the resistance of the potentiometers is too high or too low and that the Arduino thinks there is a short circuit somewhere? What can I do to resolve it and make the display work at the same time as the 6 potentiometers?
You use these as analog inputs. Most probably your display uses I2C which uses A4 and A5 on your Uno. You can not use I2C and analog inputs A4/A5 at the same time.
Can we assume this is an Uno? You should always tell the forum what type of Arduino you are using, because there are many types and they are not all the same.
What you have not learned yet is that on Uno, the i²c pins and the A4 & A5 pins appear to be separate pins, but in reality they are the same pins. They are connected on the Uno board.
If you are using any i2c devices, you can't use 2 of the analog pins as analog pins.
Can we assume your oled display has i²c interface? Something else you should always do is post a link to the components you are using so these questions don't not need to be asked. All the 128x32 oled displays I have seen have i²c interface.
In summary, if you are using an i²c device, you have only 4 analog inputs. But you need 6.
Options are:
Use an analog multiplexer chip like 74hc4051 to allow you to connect more potentiometers to the analog pins you have available.
Use an i²c ADC expander, which gives you more analog inputs. For example ads1015.
Thanks, everybody!
I understand now that my Arduino Uno (which I had mentioned to use) does not allow to use all analog inputs at the same time as the display which uses the SDA and SCL connection.
I will try the software I2C and if that doesn't work or is too slow for my purposes, I might just upgrade to a different Arduino model.
Or add a 74HC4067 muxer board.
Then you can have up to 16 pots, using only one analogue pin (and 4 for the muxer).
Add another board, and you can have 32 pots, etc.
Leo..
Haha, I have very fast fingers! Kidding, they are thick as sausages and slow.
I use the potentiometers to control six parameters for an automated expression pedal: Automate expression signal for guitar pedal
The display will show the parameters and the shape of the envelope shape that those parameters define.
I saw that @Koepel mentioned that they don't know "how much slower the software I2C is" and, to be honest, I had no clue what that could mean but I assume that it will be sufficiently fast for my purposes.
A4 and A5 are the (only) pins for using the Uno's built-in i²c hardware. If using software i²c, you can use any 2 pins you like. But software i²c is slow compared to hardware i²c, which means updating the display might be quite lethargic. Only way to know for sure is to try it.
For a project like that, it would be better to use a nano anyway, just for the smaller size and the availability of boards without headers so you can easily solder the connections.
I tried this on the Arduino Uno and the graphic output on the display does not have an acceptable quality for my project. The letters are hardly readable. Bummer. I had hoped to get around having to use a muxer board or another Arduino board.
I really want to use the Arduino Uno and not a nano because of the following reasons:
The Arduino Uno fits perfectly in the housing that I want to use for this project
It allows for 12v input rather than having to use the USB input as a power supply
The Arduino allows me to change elements easily while I would have to solder them or use a breadboard with the nano.
I have two Arduino Unos already and I don't want to buy another Arduino board for this project.
Using a software or hardware I2C bus has not to do what is on the display. The u8g2 uses a lot of memory, it can be set in a few different modes to allow it to run with less memory. You can select from many fonts. There is also a 8x8 mode without graphics.
It is possible to use a OLED with a Arduino Uno or Nano with the Adafruit or u8g2 library, just be carefull to not add another library that uses a lot of memory.
For testing purposes, I had only used a hello world text without any other libraries or processes on the Arduino. Using the display on the SDA and SCL I2C bus showed the text without any problems. Using the same code but with pin 9 and 8 instead of SDA and SCL (as you have described above: U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, 9, 8, U8X8_PIN_NONE)) shows all fonts somewhat distorted and cut off. I have no clue why that is but I could not find a font that was properly readable.