We Code, built, and share our thoughts to do chemistry

Sunday, 6 July 2025

Devlog - Building Potentiostat: Microcontrollers and I2C Conundrum

In 2024, We posted about various microcontrollers were used throughout our potentiostat developments. We expressed our frustrations on why I2C ADC and DAC were conflicted when we connected them both at the same time. It completely put setbacks on our development. As we said, we tried these connections on various microcontrollers such as WCH CH32V307, Raspberry pi pico rp2040, and STM32G0 nucleo board.  Because we do not use arduino libraries, different board have different software development kits (SDKs) which means we have to deal each of them differently and it absolutely takes so much time. Thankfully, we managed to rectify this issue despite taking quite some time. However, what matter is that it's solved and it works reliably now.

How did it go wrong? We connect the SCL and SDA directly to the breakout boards.

In our design, we used MCP4725 (12-bit Digital-to-Analog converter) and ADS1115 (16-bit analog-to-digital converter) to drive the signal and capture the voltage respectively. These devices use I2C protocol to communicate. One benefit of using I2C is that I can connect to as many as I2C devices with 2 pins (Serial Clock/SCL and Serial Data/SDA) which reduced the headache of connecting one port to another.  At the beginning of our development, we connected directly our SDA and SCL pins from our microcontrollers to each I2C breakout board. It worked out fine at first until we ran into problems later on in which the communication wasn't reliable. When we connect one of them, the device worked out okay. However, when connected both of them to our system it didn't work. It was very frustrating.

Having only I2C DAC works was actually still acceptable as we still can utilise the built-in ADC from the microcontrollers despite some limitations. One issue we encountered was the swinging reading we obtained from the measurement. It solved one problem by creating another one. Still, it could be from our end though such as our knowledge and skill-related issue but we decided to find a way to make it work. First, we replaced the DAC device. It worked again, which was great, for a short period of time. We replaced the devices multiple times but gave us the same result. It just burned our limited cash that could have been allocated for something else but we couldn't stop. Then how about we change our microntrollers? At first we developed our device using STM32F4 and WCH's CH32V307 (RISC-V microcontroller). Personally, we really enjoyed using CH32V307 as it was a dev board with built-in debugger that allowed us to see something wrong should it arise. Since it didn't work, we tried switch to Raspberry pi pico RP2040. It's a great board with dual-core capabilities but 3.3V-limited. This issue can be overcome by using level-shifter should we want to go with 5V though. The result? it was the same. Moreover, I didn't have debugger with us that we couldn't see the whole picture whether it was software-related issue. Then we thought what if the issue lied in the microcontroller reliability? we test our assumptions by changing the microcontroller to industry-standard STM32. We bought the nucleo board as it had both DAC and ADC built-in so that we can still use it from both if things went south. Well, it turned out the same.

How did we solve it eventually? Pull-up resistors and external power source (we have no idea why it works)

We did some research on why our connections didn't work the way we expected. We happened to look at the schematics that the I2C needs to connect to pull-up resistors. Then we tried it, the result was kind of similar but wait it worked out despite unreliably. We happened to have a thought, what if the microcontroller cannot drive enough current for those devices? We had power supply so why not try it? We then powered those I2C devices with power supply and it finally works! 

Here's our truncated schematics how we connect I2C devices with our microcontroller. SDA, SCL, and GND are all connected to its respective ports while Vcc is connected to the power supply. Because of that, we also need to connect both grounds of microcontroller to the grounds of power supply.

truncated schematics how we connect I2C devices with the microcontroller. The Vcc is connected to the external power supply and GND from microcontroller is also connected to the GND of the external power.



 

No comments:

Post a Comment

Our potentiostat circuit design approach compared to a glucometer

Previously, we rebuilt a potentiostat circuit to improve our design. We built it on a breadboard as we can experiment with it. You can watch...