LCD and Flowmeter Testing

A project log for Low Cost Ventilator

Low cost ventilator for standalone use during the Covid-19 pandemic

Jake WachlinJake Wachlin 03/29/2020 at 22:070 Comments

In support of our PCB design, and to test out some of the more uncertain concepts, we set up a breadboarded prototype of the LCD and the flowmeter. The main components in the prototype:

The prototype was set up as shown below. The flowmeter and LCD both require 5V power, but the flowmeter is compatible with 3.3V level I2C communication. The LCD requires logic level shifting up to 5V. The LCD also can only communicate at up to 50kHz SPI. For maximum use of this project, the hope was to set up the firmware to use Arduino API's where possible. Unfortunately, for the Feather M4, the I2C speed cannot be lowered below 100kHz using the Arduino "Wire.setClock()" interface. I had to lower the rate manually. For reference, the snippet of code for setting up the SAMD51 in slower I2C is as follows (and all this on our GitHub as we update it):

// Setup I2C at <50khz for LCD

    Wire.begin();                                     // Set-up the I2C port
    sercom2.disableWIRE();                            // Disable the I2C SERCOM

    GCLK->PCHCTRL[23].bit.CHEN = 0; // 23 is SERCOM2
    while(GCLK->PCHCTRL[23].bit.CHEN != 0);
	GCLK->PCHCTRL[23].bit.GEN = 0x04;			// Generic clock generator 4
	GCLK->PCHCTRL[23].bit.CHEN = 1;
	while(GCLK->PCHCTRL[23].bit.CHEN != 1);

    // TODO what is GCLK4 actually?
    SERCOM2->I2CM.BAUD.bit.BAUD = 48000000 / (50000) - 1;   // Set the I2C clock rate slow
    sercom2.enableWIRE();                             // Enable the I2C SERCOM  

 For the Feather M4 board, the I2C is set up for SERCOM2. The peripheral index for SERCOM2 is 23. I set up SERCOM2 to be run off of GCLK4. Underneath all the layers of Arduino, I am not quite sure yet what GCLK4's rate is. Nonetheless, I was able to get about 30kHz clock rate, as confirmed by my logic analyzer.

I set up the firmware to support:

The picture below shows the prototype setup and connections. The interface to the flowmeter was through a fairly long wire. In our design we will use an I2C driver specifically for long distance communication with high capacitance on the lines. This prototype does not have it, but still seemed reliable. The measurements have checksums and I did not see a checksum fail during testing. The flow measurements seem quite stable, and estimation of tidal volume from integrated flow rate seems reasonable.