monur
Published © GPL3+

Tweeting Plant - using atTiny85, Raspberry Pi Zero and soil

Tweeting Plant - using atTiny85, Raspberry Pi Zero and soil

IntermediateFull instructions provided947
Tweeting Plant - using atTiny85, Raspberry Pi Zero and soil

Things used in this project

Story

Read more

Schematics

Sketch

Code

attiny85 code

Arduino
Program atTiny85 using Arduino Uno
#include <SoftwareSerial.h>
#define RX    1         //  D1, Pin 6
#define TX    2         //  D2, Pin 7
#define sensorPin 3  // D3, Pin 3 
SoftwareSerial toRaspberry(RX, TX); 
void setup() {
  pinMode(sensorPin, INPUT);
  toRaspberry.begin(9600);
} 
void loop() {
  int sensorValue = analogRead(sensorPin);  
  toRaspberry.println(sensorValue);
  delay(10000);
}

Raspberry Pi Zero

Python
#!/usr/bin/env python
import time
import serial
import os
import random
import sqlite3 as sl 
def main():
  ser = serial.Serial(
   port='/dev/serial0',
   baudrate = 9600,
   parity=serial.PARITY_NONE,
   stopbits=serial.STOPBITS_ONE,
   bytesize=serial.EIGHTBITS,
   timeout=1
  )
  x = ser.readline();
  while (x == ''):
    x = ser.readline();
  print x
  checkSituation(x.rstrip()); 
def checkSituation(x):
  waterLevel = 1024 - int(x);
  tweetText = '{} --water level:{}';
  if (waterLevel < 200):
    tweetText = tweetText.format(getHelpTweet(), waterLevel);
  else:
    tweetText = tweetText.format(getFineTweet(), waterLevel);
  tweet(tweetText);
  log(waterLevel); 
def log(waterLevel):
  con = sl.connect('plant.db');
  sql = 'INSERT INTO PLANT_DATA (water_level, timestamp) values(?, ?)';
  data = (waterLevel, int(time.time()));
  con.execute(sql, data);
  con.commit();
  con.close(); 
def tweet(text):
  command = 'twidge update "{}"'.format(text);
  os.system(command);
  print(command); 
def getFineTweet():
  fines = ["I'm doing fine today :)",
         "It's a beautiful day ;)",
         "I love my pot :)"];
  return random.choice(fines); 
def getHelpTweet():
  helps = ["I need water!! :(",
           "Somebody give me water, please",
           "Anyone there to water me? :("]
  return random.choice(helps); 
if __name__ == "__main__":
  main()

Credits

monur

monur

0 projects • 0 followers

Comments