10-channel voltage logger with LCD and SD card

In this video, I show you how to implement a 10-channel voltage logger with an LCD and an SD card using a STM32F401CCU6 microcontroller. This project will also serve as a “backbone” for some of my upcoming projects.

I picked this microcontroller because it is not much more expensive than an Arduino Nano, but it is much much more powerful. It has more IO pins, more peripherals, it has more computational power, higher ADC resolution (12-bits), and many more… It is a totally different world. I made several projects with this microcontroller already, for example, I used it as a driver for the TCD1304 linear CCD.



Technical details

The circuit is actually quite simple. However, there is some know-how in the project because even though it is a simple project, a few steps are not super straightforward.

As a display, I am using this generic 1.8 TFT LCD with SD card slot display. It is an SPI display that can be driven with Adafruit’s ST7735 library. The SD card module of the display also uses SPI, and thus one would think that these two could share the same SPI bus, however, it is unfortunately not the case. I played around with the code and the connections and each time I started logging onto the SD card, the display froze, and then the whole program became unresponsive. Funnily enough, the SD card still contained the data and I could see the fresh data on the serial port. The only issue was that the LCD became unresponsive. I spent hours with Googling other people’s experiences. It turned out that the SD card “hijacks” the SPI and when the code would want to return to the LCD, it just can not. This seems to be a hardware issue related to the LCD’s SPI connections. I was too lazy to solve it with hardware, so I simply sacrificed 3 additional pins (MISO, MOSI, SCK) and used another SPI bus for the SD card.

So, with this approach, the display is running on SPI 3 and the SD card is running on SPI 2. SPI 1 is not available, because those pins (PA7-PA4) are occupied by the ADC channels.

The setup also contains a button. I used a single button to navigate in the menu and start/stop logging. The principles are simple. A short button press moves forward in the menu, and a long button press interacts with the active menu item. For example, if we press the button for more than 1 second when the start button is highlighted, then the logging starts and the data is saved on the SD card. This is carefully explained in the video.

Another thing to consider is that this device is based on 3.3 V levels. According to its datasheet, the digital IO pins are 5 V-tolerant but for example, the ADC pins are not really compatible with 5 V as they are analogue IO. So let’s stick with the 3.3 V for all the pins and then we are on the safe side. This 3.3 V also becomes the reference voltage of the ADC. Since the device has a 12-bit ADC, the resolution becomes 3.3 V / 4096 → 806 uV. This is a fantastic resolution for most of the hobby projects in my opinion. Even if we would add a x10 multiplier by adding a voltage divider to the input to extend the input voltage to 33 V, the resolution would be 8.057 mV which is still quite good especially if we consider the range.

Here comes another thing that we need to take care of. By default, the ADC resolution is set to 10 bits. So, in the setup() part of the Arduino code we must state that we want to use the ADC at 12-bits. This is explained in the video.



 

For a full, copy-pasteable code, please consider becoming my Patreon!

 

Sketch of the voltage logger connections. The LCD and the SD card use two different SPI buses. The ADC channels are between pins B1 (channel 1) and A0 (channel 10). Remember, that the maximum voltage that can be directly connected to the analogue input is 3.3 V! There is also a push button in the sketch indicated with SW. The pin of the push button (B6) is high by default (INPUT_PULLUP), and when it is pressed, it goes low because B6 gets shorted to the ground.


Previous
Previous

10-channel NTC-based temperature logger

Next
Next

Strain gauge, Wheatstone bridge, differential amplifier - Educational device