Dear folk,
I have a question for how to display my MLX90614 IR temperature module reading to my 16x32 LED array module. My LED module was communicated through UART as it has STM8S003 MCU inside. And it requires to send character in ASCII in below format:
byte showASCII[9]=
{
8,//length
0x8D,0x40,0xD7,0xBF,//module address
0x09,//command line
0x00,//X-cordinate
0x00,//Y-cordinate
0x41 //The ASCII code will be displayed("A" as example)
void printCmd(byte cmd[],int len1)
{
for(int i=0;i<len1;i++){
Serial3.write(cmd[i]);
}
}
void setup() {
Serial.begin(9600);
Serial3.begin(9600);//LED Port
};
void loop() {
printCmd(showASCII,9);
}
I can read MLX90614 IR temperature value by:
int temp = mlx.readObjectTempC();
Can anyone teach me how to convert my temp value to ASCII then put into showASCII and display by my LED module? Really appreciated!
After a long day study, I finally solve the problem. Here below is my code in case if anyone also has same question.
#include <Adafruit_MLX90614.h> //thermal
Adafruit_MLX90614 mlx = Adafruit_MLX90614(); //thermal
#include <Wire.h> //I2C for thermal module
//Show ASCII
byte cmdShowAscii1[9]={
8,
0xD3,0x84,0x5D,0x8C,//LED1 module serial no.
0x09,0x06,
0x00,0x00
};
byte cmdShowAscii2[9]={
8,
0x8D,0x40,0xD7,0xBF,//LED2 module serial no.
0x09,0x06,
0x00,0x00
};
byte sendAsciiChar1(byte x1, byte y1, byte ch1) //LED1 module serial no.
{
cmdShowAscii1[6] = x1;
cmdShowAscii1[7] = y1;
cmdShowAscii1[8] = ch1;
Serial3.write(cmdShowAscii1, 9);
};
byte sendAsciiChar2(byte x2, byte y2, byte ch2) //LED2 module serial no.
{
cmdShowAscii2[6] = x2;
cmdShowAscii2[7] = y2;
cmdShowAscii2[8] = ch2;
Serial2.write(cmdShowAscii2, 9);
};
int a=0;
int a_max=3000; //define the sampling rate
void setup() {
pinMode(pin1, INPUT);
pinMode(pin2, INPUT);
pinMode(SWITCH_PIN, INPUT);
Serial.begin(9600);
Serial3.begin(9600);//LED1 UART Port //LED1 module
Serial2 .begin(9600);//LED2 UART Port //LED2 module
mlx.begin(); //thermal
Wire.begin();
}
void loop() {
a=a+1;
if(a==a_max){
int temp = mlx.readObjectTempC();
int t1 = temp%10; //to get digits
int t2 = (temp/10)%10; //to get ten digits
int t3 = (temp/100)%10; //to get hundred digits
sendAsciiChar2(7,0,(t1+0x30));
delay(30);
sendAsciiChar2(1,0,(t2+0x30));
if(t3 != 0){ //show only if hundred digits not zero
delay(30);
sendAsciiChar1(11,0,(t3+0x30));
Serial.print(t3);
}else{
delay(30);
sendAsciiChar1(11,0,' '); //if temp<100 display space instead
}
Serial.print(t2);
Serial.println(t1);
a=0;
}
}