Dear Arduino Community,
I am reading CO2 values from a CO2 sensor and want to send these files to the Arduino Cloud. Via the MKR NB1500 + sim everything works fine beside frequent break up (the reason why I would like to switch to Nano 33 IOT Wifi Version).
With a simple test code the Arduino Nano 33 IOT is also connecting to Wifi, however once I combine the code (Wifi Application + Sensor readout) the device is simply not establishing a Wifi Connection anymore...
***** Arduino IoT Cloud - configuration info *****
Device ID: 92a1f313-19b8-4b74-9de5-1adbb544469a
MQTT Broker: iot.arduino.cc:8883
WiFi.status(): 0
Current WiFi Firmware: 1.5.0
Does this might have something to do with the serial communication?
SSID and PW is definitly correct.
Any help is greatly apprechiated <3
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
int co2tocloud;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
/*
Pin connections:
Arduino Nano 33 IOT________COZIR Sensor
GND ------------------- GND
VCC(3.3v) ------------------- VCC(3.3v)
TX ------------------- RX
RX ------------------- TX
*/
int co2 =0;
int CO2Value =0;
double multiplier = 10;// 1 for 2% =20000 PPM, 10 for 20% = 200,000 PPM
uint8_t buffer[25];
uint8_t ind =0;
uint8_t indexi =0;
int fill_buffer(); // function prototypes here
int format_output();
#include "thingProperties.h"
void setup() {
Serial.begin(9600);
delay(5000);
Serial1.begin(9600);
delay(5000);
Serial1.println("M 6"); // send Mode for Z and z outputs "Z xxxxx z xxxxx" (CO2 filtered and unfiltered)
Serial1.println("K 1"); // set streaming mode
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 4 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update(); // initialize Arduino Cloud Service
fill_buffer(); // function call that reacds CO2 sensor and fills buffer
for(int j=0; j<ind; j++);
indexi = 8; // In ASCII buffer, filtered value is offset from raw by 8 bytes
format_output();
}
int fill_buffer(void){
// Fill buffer with sensor ascii data
ind = 0;
while(buffer[ind-1] != 0x0A){ // Read sensor and fill buffer up to 0XA = CR
if(Serial1.available()){
buffer[ind] = Serial1.read();
ind++;
}
}
// buffer() now filled with sensor ascii data
// ind contains the number of characters loaded into buffer up to 0xA = CR
ind = ind -2; // decrement buffer to exactly match last numerical character
}
int format_output(void){ // read buffer, extract 6 ASCII chars, convert to PPM and print
co2 = buffer[15-indexi]-0x30;
co2 = co2+((buffer[14-indexi]-0x30)*10);
co2 +=(buffer[13-indexi]-0x30)*100;
co2 +=(buffer[12-indexi]-0x30)*1000;
co2 +=(buffer[11-indexi]-0x30)*10000;
CO2Value = co2*multiplier;
if (CO2Value >= 0 && CO2Value <= 200000) {
Serial.println(co2*multiplier,0);
co2tocloud = co2*multiplier;
delay(1000);
} else {
// Do nothing
}
}