Display multiple sensor values on an LCD with an attiny85
Use an ATtiny85 to display sensor values on an I2C LCD (equiped with PCF8574): GY21P (Si7021+SHT21) I2C sensor, temperature and relative humidity DS18b20 Dallas sensor, one wire, temperature
I had tried to use an ATtiny85 and a 2X16_I2C LCD, but the compilation revealed a multitude of warnings.
I'm not a fan of warning, so I left the idea on hold.
The need for simple and mobile temperature/humidity measurement and display challenged me.
I started by reviewing the LiquidCrystal_ATtiny library and validated the _revBC version
A first test code uploaded to the Attiny is satisfactory.
TEST_I2C_LCD_ATtiny85
it is a simple counter up to 1000, displayed on the LCD, which confirms correct operation.
I carried out a second step, adding a shield sensor GY21P (Si7021+SHT21) which returns temperature and humidity.
NOTE::
the GY21P shield is powered by 5V!!
A voltage regulator type XC6206 (662K_reg3V3) is on board. (see data sheet)
Some functions from the Si7021 library have been adapted and installed in the code.
TEST_I2C_Si7021_LCD_ATtiny85_v2
The satisfactory results, remaining a few usable pins on the ATtiny,
I added a DS18B20 sensor with an identical reading to the ATtiny_Fan mount
see Lab : Variateur for 12V ventilator or Fan
The code uses the ISR WDT Watch Dog to count and validate the measurement reading
We interrogate the GY21P which returns temperature and humidity, then the Dallas Ds18B20 sensor.
The measures values are displayed.
TEST_I2C_DS18B20_Si7021_LCD_ATtiny85_v2
You can use and modify these three codes or all codes at your convenience.
short video here :
Only Si7021
https://youtu.be/FP8w9qeFBvM
SI7021 and DS18B20
https://youtu.be/dF9ZkFui-zM
///FR
Utiliser un ATtiny85 pour afficher sur un LCD I2C les valeurs de capteurs :
GY21P (Si7021+SHT21) capteur I2C, température et humidité relative
DS18b20 capteur Dallas, One wire, température
J'avais tenté d'utiliser un ATtiny85 et un LCD 2X16_I2C, mais la compilation laissait apparaître une multitude de warning.
Je ne suis pas un fan de warning, aussi j'ai laissé l'idée en pause.
Le besoin de mesure et affichage de température/humidité simple et mobile m'a remis à l'épreuve.
J'ai commencé par revoir la librairie LiquidCrystal_ATtiny et validé la version _revBC
Un premier code de test téléversé dans l'Attiny donne satisfaction.
TEST_I2C_LCD_ATtiny85
C'est un simple compteur jusqu'à 1000, affiché sur le LCD, qui confirme le bon fonctionnement.
J'ai réalisé une deuxième étape, ajouter un capteur shield GY21P (Si7021+SHT21) qui retourne température et humidité.
NOTA ::
le shield GY21P s'alimente en 5V !!
Un régulateur de tension type XC6206 (662K_reg3V3) y est embarqué.(voir data sheet)
Quelques fonctions issues de la librairie Si7021 on été adaptées et installées dans le code.
TEST_I2C_Si7021_LCD_ATtiny85_v2
Les résultats donnant satisfaction, restant quelques pins utilisables sur l'ATtiny,
j'ai ajouté un capteur DS18B20 avec une lecture identique au montage ATtiny_Fan
voir Lab : Variateur for 12V ventilator or Fan
Le code utilise les ISR WDT Watch Dog pour compter et valider le relevé de mesures
On interroge le GY21P qui retourne température et humidité, puis le capteur dallas Ds18B20.
On affiche les valeurs de mesures.
TEST_I2C_DS18B20_Si7021_LCD_ATtiny85_v2
Vous pouvez utiliser et modifier à votre convenance un des trois code... ou les trois !
short vidéo ici :
Si7021 seulement
https://youtu.be/FP8w9qeFBvM
SI7021et DS18B20
https://youtu.be/dF9ZkFui-zM
I'm not a fan of warning, so I left the idea on hold.
The need for simple and mobile temperature/humidity measurement and display challenged me.
I started by reviewing the LiquidCrystal_ATtiny library and validated the _revBC version
A first test code uploaded to the Attiny is satisfactory.
TEST_I2C_LCD_ATtiny85
it is a simple counter up to 1000, displayed on the LCD, which confirms correct operation.
I carried out a second step, adding a shield sensor GY21P (Si7021+SHT21) which returns temperature and humidity.
NOTE::
the GY21P shield is powered by 5V!!
A voltage regulator type XC6206 (662K_reg3V3) is on board. (see data sheet)
Some functions from the Si7021 library have been adapted and installed in the code.
TEST_I2C_Si7021_LCD_ATtiny85_v2
The satisfactory results, remaining a few usable pins on the ATtiny,
I added a DS18B20 sensor with an identical reading to the ATtiny_Fan mount
see Lab : Variateur for 12V ventilator or Fan
The code uses the ISR WDT Watch Dog to count and validate the measurement reading
We interrogate the GY21P which returns temperature and humidity, then the Dallas Ds18B20 sensor.
The measures values are displayed.
TEST_I2C_DS18B20_Si7021_LCD_ATtiny85_v2
You can use and modify these three codes or all codes at your convenience.
short video here :
Only Si7021
https://youtu.be/FP8w9qeFBvM
SI7021 and DS18B20
https://youtu.be/dF9ZkFui-zM
///FR
Utiliser un ATtiny85 pour afficher sur un LCD I2C les valeurs de capteurs :
GY21P (Si7021+SHT21) capteur I2C, température et humidité relative
DS18b20 capteur Dallas, One wire, température
J'avais tenté d'utiliser un ATtiny85 et un LCD 2X16_I2C, mais la compilation laissait apparaître une multitude de warning.
Je ne suis pas un fan de warning, aussi j'ai laissé l'idée en pause.
Le besoin de mesure et affichage de température/humidité simple et mobile m'a remis à l'épreuve.
J'ai commencé par revoir la librairie LiquidCrystal_ATtiny et validé la version _revBC
Un premier code de test téléversé dans l'Attiny donne satisfaction.
TEST_I2C_LCD_ATtiny85
C'est un simple compteur jusqu'à 1000, affiché sur le LCD, qui confirme le bon fonctionnement.
J'ai réalisé une deuxième étape, ajouter un capteur shield GY21P (Si7021+SHT21) qui retourne température et humidité.
NOTA ::
le shield GY21P s'alimente en 5V !!
Un régulateur de tension type XC6206 (662K_reg3V3) y est embarqué.(voir data sheet)
Quelques fonctions issues de la librairie Si7021 on été adaptées et installées dans le code.
TEST_I2C_Si7021_LCD_ATtiny85_v2
Les résultats donnant satisfaction, restant quelques pins utilisables sur l'ATtiny,
j'ai ajouté un capteur DS18B20 avec une lecture identique au montage ATtiny_Fan
voir Lab : Variateur for 12V ventilator or Fan
Le code utilise les ISR WDT Watch Dog pour compter et valider le relevé de mesures
On interroge le GY21P qui retourne température et humidité, puis le capteur dallas Ds18B20.
On affiche les valeurs de mesures.
TEST_I2C_DS18B20_Si7021_LCD_ATtiny85_v2
Vous pouvez utiliser et modifier à votre convenance un des trois code... ou les trois !
short vidéo ici :
Si7021 seulement
https://youtu.be/FP8w9qeFBvM
SI7021et DS18B20
https://youtu.be/dF9ZkFui-zM
Updates van de auteur
Arduino47 1 jaar geleden
TEST_I2C_Si7021_LCD_ATtiny85_v3
At start-up, the CPU is initialized, the sensor data is read and displayed.
We delay via the delay(5000) function the actions reading sensor data
----------------------------------
TEST_I2C_DS18B20_Si7021_LCD_ATtiny85_v3
At start-up, the CPU is initialized, the sensor data is read and displayed.
Actions taken to read sensor data are timed via the watchdog.
----------------------------------
ISR_SLEEP_MODE_LCD_ATTINY_v2
We use timer 0 to simulate the millis() function
We use the ISR PCINT to wake up the system
At startup, the CPU is initialized, the sensor data is read and displayed for the defined delay time.
The duration has expired, power off the elements (LCD SI7021) and the CPU goes into sleep mode.
If touch button detection, by the ISR PCINT, we wake up the whole thing for the defined tempo duration.
---------------------------------
//FR
Pour bien récapituler au 30/08/2023:
TEST_I2C_Si7021_LCD_ATtiny85_v3
Au démarrage on initialise l'UC, on relève les datas capteurs et on affiche.
On temporise via la fonction delay(5000) les actions releve datas capteur
----------------------------------
TEST_I2C_DS18B20_Si7021_LCD_ATtiny85_v3
Au démarrage on initialise l'UC, on relève les datas capteurs et on affiche.
On temporise via le chien de garde les actions releve datas capteurs
----------------------------------
ISR_SLEEP_MODE_LCD_ATTINY_v2
On utilise le timer 0 pour simuler la fonction millis()
On utilise l'ISR PCINT pour réveiller le système
Au démarrage on initialise l'UC, on relève les datas capteurs et on affiche durant la durée de temporisation définie.
La durée est écoulée, power off des eléménts (LCD SI7021) et l'UC passe en mode sleep.
Si détection touche tactile, par l'ISR PCINT, on réveil l'ensemble pour la durée de tempo définie.
---------------------------------
Arduino47 1 jaar geleden
https://siliconlabs.github.io/Gecko_SDK_Doc/efm32g/html/si7021_8c_source.html
Where it is written :
*rhData = ((uint32_t) readData[0] << 8) + (readData[1] & 0xfc);
*tData = ((uint32_t) readData[0] << 8) + (readData[1] & 0xfc);
So I reviewed the code like this:
measureCode = (uint16_t)(dataBrut[0] << 8) | (dataBrut[1] & 0xfc);
1. (dataBrut[1] & 0xfc): performs bit masking on the least significant (dataBrut[1] = LSB) so as to keep only the most significant 6 bits and set the two least significant bits to zero.
2. measureCode = (uint16_t)(dataBrut[0] << 8) | (dataBrut[1] & 0xfc); :
This line combines the bytes dataBrut[0] = MSB and dataBrut[1] & 0xfc = LSB&0xFC to form a 16-bit value (uint16_t).
The MSB bytes are shifted left by 8 bits (dataBrut[0] << 8) to make room for the LSB bytes.
Then the binary left shift operator (|) is used to combine the bits of the MSB and LSB bytes, thus forming the 16-bit value.
The code has been corrected and reviewed as a whole, adhering to the manufacturer's specifications.
TEST_I2C_Si7021_LCD_ATtiny85_v3
TEST_I2C_DS18B20_Si7021_LCD_ATtiny85_v3
ISR_SLEEP_MODE_LCD_ATTINY_v2
ZIP NEW CODES
//FR
En cherchant comment utiliser le troisième octet disponible, et aussi pourquoi ce projet a été dépouillé de ses étoiles, j'ai trouvé cette page :
https://siliconlabs.github.io/Gecko_SDK_Doc/efm32g/html/si7021_8c_source.html
Où il est écrit :
*rhData = ((uint32_t) readData[0] << 8) + (readData[1] & 0xfc);
*tData = ((uint32_t) readData[0] << 8) + (readData[1] & 0xfc);
J'ai donc révisé le code comme ceci :
MeasureCode = (uint16_t)(dataBrut[0] << 8) | (dataBrut[1] & 0xfc);
1. (dataBrut[1] & 0xfc) : effectue un masquage des bits sur le poids faible (dataBrut[1] = LSB) de manière à ne conserver que les 6 bits de poids fort et à mettre à zéro les deux bits de poids faible.
2. MeasureCode = (uint16_t)(dataBrut[0] << 8) | (dataBrut[1] & 0xfc); :
Cette ligne combine les octets dataBrut[0] = MSB et dataBrut[1] & 0xfc = LSB&0xFC pour former une valeur de 16 bits (uint16_t).
Les octets MSB sont décalés vers la gauche de 8 bits (dataBrut[0] << 8) pour faire de la place aux octets LSB.
Ensuite, l'opérateur de décalage binaire vers la gauche (|) est utilisé pour combiner les bits des octets MSB et LSB, formant ainsi la valeur de 16 bits.
Les codes ont été corrigés et revus dans leur ensemble, en respectant les spécifications du fabricantt.
TEST_I2C_Si7021_LCD_ATtiny85_v3
TEST_I2C_DS18B20_Si7021_LCD_ATtiny85_v3
ISR_SLEEP_MODE_LCD_ATTINY_v2
ZIP NEW CODES
Arduino47 1 jaar geleden
Putting the CPU into sleep mode.
Power on/off of Si7021 and LCD elements via an NPN transistor (PB1 PIN6)
Touch sens TTP223 or a B.P. to exit sleep mode. TTP223 key (PB4 PIN3)
NOTE: if B.P. put a 10K resistor in pullDown mode, see diagram
At the first start of the CPU, we do the isr setup, we activate the elements via power ON, we will do the setup of the objects then we will read the values of the sensor and T°C and RH% are displayed on the LCD during the time delay that can be modified via the definition TEMPO_DISPLAY (60000) ex: 60000=1mns -> display duration
Display time elapsed, the elements are cut (Si and Lcd) and the CPU goes into sleep mode.
If action Touch (or bp), we activate the elements via power ON, we will do the setup of the objects then we will read the values of the sensor T°C and RH% are displayed on the LCD
Display time elapsed, the elements are cut (Si and Lcd) and the CPU goes into sleep mode.
FR ::
Addition :
Mise en mode sommeil de l'UC.
Power on/off des éléments Si7021 et LCD via un transistor NPN (PB1 PIN6)
Touch sens TTP223 ou un B.P. pour sortir du mode sleep. Touche TTP223 (PB4 PIN3)
NOTE : si B.P.mettre une résistance de 10K en mode pullDown, voir schema
Au premier démarrage de l'UC, on fait le setup isr, on active les éléments via power ON, on va faire le setup des objets puis on va lire les valeurs du capteur et on affiche sur le LCD T°C et HR% durant la temporisation modifiable via
la définition TEMPO_DISPLAY (60000) ex: 60000=1mns -> durée d'affichage
Durée d'affichage écoulée, on coupe les éléments (Si et Lcd) et l'UC se met en mode sleep.
Si action Touch (ou bp), on active les éléments via power ON,
on va faire le setup des objets puis on va lire les valeurs du capteur
on affiche sur le LCD T°C et HR%
Durée d'affichage écoulée, on coupe les éléments (Si et Lcd) et l'UC se met en mode sleep.
Arduino47 2 jaar geleden
So I reviewed the way to read the data from the Si7021 sensor.
This results in two revised codes concerning the Si7021 measurement only :
LiquidCrystal_ATtiny_revBC.zip
TEST_I2C_Si7021_LCD_ATtiny85_v2
TEST_I2C_DS18B20_Si7021_LCD_ATtiny85_v2
By the way, I make you enjoy my assembly with a modified HW260 shield.
See : Assembly_ATTINY_SI_DS_LCD_My_Exemple.pdf
//FR
Des valeurs d'humidité relative négative ont été affichées sur mon LCD. Ce n'est pas normal.
J'ai donc revu la manière de lire les données issues du capteur Si7021.
Il en résulte deux code révisités concernant la mesure Si7021 seulement :
Les codes se trouvent dans le dossier LiquidCrystal_ATtiny_revBC.zip
TEST_I2C_Si7021_LCD_ATtiny85_v2
TEST_I2C_DS18B20_Si7021_LCD_ATtiny85_v2
Au passage, je vous fait profiter de mon assemblage avec un shield HW260 modifié.
Voir : Assembly_ATTINY_SI_DS_LCD_My_Exemple.pdf