c++ – Downside insert Information from arduino to raspberry pi sqlite3 database-python

i've the arduino code and that i wish to ship the info to raspberry pi and save them right into a database sqlite- python . I join the arduino to raspberry pi with USB

#embody <LiquidCrystal_I2C.h>
#embody <LCD.h>
#embody <Wire.h>
#embody <SimpleDHT.h>


int pinDHT11 = 2;
SimpleDHT11 dht11(pinDHT11);

int SoilPin = 1; //soil sensor Analog pin 0
int SoilValue = 0;

#outline VIN 5 // V energy voltage
#outline R 10000 //10 Kohm resistance worth
int LdrPin = A0; // Pin related to ldr sensor
int LdrVal; // Analog worth from the ldr sensor
int lux; //Lux worth
int sensorRawToPhys(int uncooked){  // Conversion rule
  float Vout = float(uncooked) * (VIN / float(1023));// Conversion analog to voltage
  float RLDR = (R * (VIN - Vout))/Vout; // Conversion voltage to resistance
  int phys=500/(RLDR/1000); // Conversion resitance to lumen
  return phys;
}
 
int waterPump=3;
int led1 = 4;
int led2 = 5;

LiquidCrystal_I2C liquid crystal display(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);



void setup() {
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode (waterPump,OUTPUT);
 liquid crystal display.start(20, 4); // arrange the LCD's variety of columns and rows,20x4 liquid crystal display οθόνη 
 Serial.start(9600);//Arduino to serial monitor
}



void loop() {
    
byte temp = 0;
byte hum = 0;
  int err = SimpleDHTErrSuccess;
  if ((err = dht11.learn(&temp, &hum, NULL)) != SimpleDHTErrSuccess) {
    Serial.print("Learn DHT11 failed, err="); Serial.print(SimpleDHTErrCode(err));
    Serial.print(","); Serial.println(SimpleDHTErrDuration(err)); delay(1000);
    return;}
liquid crystal display.setCursor(0,1);
liquid crystal display.print("Temp= ");
liquid crystal display.print((int)temp); 
liquid crystal display.print("oC");
liquid crystal display.setCursor (0,0);
liquid crystal display.print ("Hum= ");
liquid crystal display.print((int)hum); 
liquid crystal display.print(" % ");



liquid crystal display.setCursor(0,2);
SoilValue = map(analogRead(SoilPin), 1023, 0, 0, 100); 
liquid crystal display.print("Soil Moist= ");
liquid crystal display.print(SoilValue);
liquid crystal display.print(" % ");

liquid crystal display.setCursor(0,3);
LdrVal = analogRead(LdrPin);
lux=sensorRawToPhys(LdrVal);
liquid crystal display.print("Gentle = ");
liquid crystal display.print(lux);  
liquid crystal display.print(" lumen ");



//Ship temperature and humidity information to Raspberry Pi
  Serial.println("Sensor Monitoring System");
  Serial.print("Temperature= ");
  Serial.print(temp);
  Serial.println("oC");
  Serial.print("Humidity= ");
  Serial.print(hum);
  Serial.println("%");
  Serial.print("Gentle= ");
  Serial.print(lux);
  Serial.println(" lumen");
  Serial.print("Soil moisture= ");
  Serial.print(SoilValue);
  Serial.println("%");


  
if (SoilValue > 40) {  
  digitalWrite(waterPump,HIGH); 
  digitalWrite(led1, HIGH); 
  digitalWrite(led2, LOW); 
}  
else {
    digitalWrite(waterPump,LOW); 
    digitalWrite(led1, LOW);  
    digitalWrite(led2, HIGH); 
  } 


delay(5000); 

} 

The primary half which is the show of the info right into a raspberry pi with python is prepared.

Python code: If i run this code it's going to present me the Information on CMD of raspberry pi

import serial

ser = serial.Serial('/dev/ttyUSB0',9600)

whereas True:

    read_serial=ser.readline()

    print(read_serial)

That is the sqlite db

pi@raspberrypi:~ $ sqlite3 SensorsData.db
SQLite model 3.27.2 2019-02-25 16:06:06
Enter ".assist" for utilization hints.
sqlite> .schema
CREATE TABLE DHT_data (timestamp DATETIME, temp NUMERUC, hum NUMERIC);
CREATE TABLE SOIL_data (timestamp DATETIME, lux NUMERIC);
CREATE TABLE LUX_data (timestamp DATETIME, lux NUMERIC);
sqlite> .desk
DHT_data   LUX_data   SOIL_data
sqlite> 

I do not know the right way to insert the info into an sqlite db. The one examples I discovered on the web are with the sensors being related to raspberry pi itself, so i cant perceive what ought to I do on the sqlite.

Sorry for my arduino code if it's not writen effectively, however it's working simply nice

Thank's upfront



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *