Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5041

General • How to interrupt using RS485-TTL

$
0
0
Hello everybody, I am using Arduino IDE to read data from sensor which measure temperature, humidity and CO2 concentration. The module for RE485-TTL has 4 pins on side (Vcc, Gnd, Rx and Tx0 while on the other side also has 4 pins (Vcc, A+, B- and Gnd). Below is the program for Pico W

Code:

#include <Wire.h>#include <SoftwareSerial.h>#include <SPI.h>const byte CWTAll_request[] = { 0x01, 0x03, 0x00, 0x00, 0x00, 0x03, 0x05, 0xCB };  // inquiry framebyte CWTALL_buf[11];float tempC;  //sementaraint tempold,tempnew, humold,humnew,co2old,co2new;volatile int temp;volatile int humd;volatile int co2;void setup() {  // put your setup code here, to run once:  Serial1.setTX(16);  Serial1.setRX(17);  Serial1.begin(4800);  Serial.begin(9600);  Serial.println("CWT CO2,Temp & Humidity");  tempnew = 0;  humnew = 0;  co2new = 0;  attachInterrupt(digitalPinToInterrupt(17), readvalue, CHANGE);  delay(1000);}void readvalue(){  Serial1.write(CWTAll_request, sizeof(CWTAll_request));  Serial1.flush();  Serial1.readBytes(CWTALL_buf,11);  humd = (CWTALL_buf[3] << 8) | CWTALL_buf[4];  temp = (CWTALL_buf[5] << 8) | CWTALL_buf[6];  co2 = (CWTALL_buf[7] << 8) | CWTALL_buf[8];}void loop() {  // put your main code here, to run repeatedly:   tempC = analogReadTemp();  Serial.println(tempC);  /* Trial for interrupt  Serial1.write(CWTAll_request, sizeof(CWTAll_request));  Serial1.flush();  Serial1.readBytes(CWTALL_buf,11);  unsigned humid = (CWTALL_buf[3] << 8) | CWTALL_buf[4];  Serial.print(" ");  Serial.print("Humidity: ");  Serial.print(String(humid/10) + "%");  Serial.print("--");  unsigned temper = (CWTALL_buf[5] << 8) | CWTALL_buf[6];  Serial.print(" ");  Serial.print("Tem: ");  Serial.print(String(temper/10) + "C");  Serial.print("--");  unsigned karbon = (CWTALL_buf[7] << 8) | CWTALL_buf[8];  Serial.print(" ");  Serial.print("C02: ");  Serial.print(String(karbon) + "ppm");  Serial.println("  ");   */  // from interrupt  Serial.print(humd);  Serial.print("---");  Serial.print(temp);  Serial.print("---");  Serial.println(co2);  Serial.println("********** ");  delay(2000);}
From the above program, as in the loop(), it works (before it was commented). It was commented to test for interrupt, but did not work. Any idea to solve this problem?

Statistics: Posted by rais — Fri May 10, 2024 7:47 am



Viewing all articles
Browse latest Browse all 5041

Trending Articles