Greetings, here lies my work-log at

______ _ ___ _ _____ _____ __ ______ | ___| | | / _ \ | | / __ \| _ |/ | |___ / | |_ __ _| |__ / /_\ \ ___ __ _ __| | ___ _ __ ___ _ _ `' / /'| |/' |`| | / / | _/ _` | '_ \| _ |/ __/ _` |/ _` |/ _ \ '_ ` _ \| | | | / / | /| | | | / / | || (_| | |_) | | | | (_| (_| | (_| | __/ | | | | | |_| | ./ /___\ |_/ /_| |_./ / \_| \__,_|_.__/\_| |_/\___\__,_|\__,_|\___|_| |_| |_|\__, | \_____/ \___/ \___/\_/ |_|


input devices



index



/Assignment goals

/Intro / overview

sensors galore, for this week - i wanted to try as many sensors as possible, due to limited time, at the end I managed to design and stuff a hello.world.DHT22 sensor attiny45 based board. I also designed a board called hello.sniffer which is an attiny44 based gas sensor board



Learning's from Datasheet

The pinout diagram from the datasheet is what I used to pick the digital pin I needed to be the ADC (Analog to Digital Converter)


I selected PB2 - it is a general I/O port and the description is as follows


While doing ADC , it is generally recommended to use an external clock for better accuracy, so i looked into the clock systems mentioned in the datasheet, but however later decided to try the board on the internal clock first, to see how much the internal clock's inaccuracy affects the readings


I used arduino libraries and the arduino IDE to program the board - the command to intitialize Analog reading is 'analogRead'

define tempPin A1 //Defining the pin A1 as the data pin
int val; 
void setup()
{
  myserial.begin(9600); //serial begins at 9600 baud rate
  pinMode(A1, INPUT);  //pin A1 becomes an input now
}

void loop()
{
  val = analogRead(tempPin); 
  float mv = ( val / 1024.0) * 5000; //mapping analog values to relevant temperature readings
  float cel = mv / 10; 
  float farh = (cel * 9) / 5 + 32; //farh to cel conversion

  myserial.print((char)cel);  
  delay(10); 
}

ALl the alternate functions of each pin, the one I need is a pin with ADC


Details on how to toggle pins to different states


Basic overview of ADC features of an ADC pin


This is the block diagram of the ADC, fascinating stuff


The chip has an in-built temperature sensor but it can't be put to service as a temperature sensor like LM35



/Designing the board and stuffing it

This is the pproject home of this design, the file tree shows the library cache, the netlist, the schematic and the PCB design


This is the CvPCB window where all the components you have added to your schematic will need to be assigned footprints here


After assigning footprints, one has to generate the netlist and then read that netlist in PCBnew - which is the PCB layout software


This is the final schematic


This is the final PCB footprint layout with traces


invoking the compiled version of FabModules


Selecting the 1/64 profile to mill traces


Selecting the 1/32 profile to cut edges


Milled boards :)


View post on imgur.com



/Programming workflow

Used arduino Uno as ISP


    #include 

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, modified for integer use, public domain

#include "TinyDHT.h"

#define DHTPIN 2  // DHT connected to Arduino Uno Digital Pin 2

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11 
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)


// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) 
//    of the sensor

DHT dht(DHTPIN, DHTTYPE);

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {
  mySerial.begin(9600); // Output status on Uno serial monitor
  mySerial.println("DHTxx test!");
 
  dht.begin();
}

void loop() {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  int8_t h = dht.readHumidity();
  int16_t t = dht.readTemperature(1);

  // check if returns are valid then something went wrong!
  if ( t == BAD_TEMP || h == BAD_HUM ) { // if error conditions          
    mySerial.println("Failed to read from DHT");
  } else {
    mySerial.print("Humidity: "); 
    mySerial.print(h);
    mySerial.print(" %\t");
    mySerial.print("Temperature: "); 
    mySerial.print(t);
    mySerial.println(" *C");
  }
  delay(2000);
}

A point to note is that the standard DHT library is too big with the software serial library to fit in the flash memory of the attiny40s, so, I've used anpother variant of the lbrary called TinyDHT which uses int values instead of heavier float values

But alas the sensor turned out to be faulty (i'm to blame mostly) :/



/switching from the DHT22 to LM35

My DHT22, I suspect is whack after I've handled it roughly; so I decided to replace it with an LM35 temperature sensor

with similar pinouts, I resorted to using the same board for the LM35 sensor.



code for LM35


#include //library to replace hardware serial

SoftwareSerial myserial(3, 4); // TX and RX pins (transmit and recieve)

#define tempPin A1 //Defining the pin A1 as the data pin
int val; 
void setup()
{
  myserial.begin(9600); //serial begins at 9600 baud rate
  pinMode(A1, INPUT);  //pin A1 becomes an input now
}

void loop()
{
  val = analogRead(tempPin); 
  float mv = ( val / 1024.0) * 5000; //mapping analog values to relevant temperature readings
  float cel = mv / 10; 
  float farh = (cel * 9) / 5 + 32; //farh to cel conversion

  myserial.print((char)cel);  
  delay(10); 
}



programming and demo

/File downloads



/conclusion

A whole world of sensing possibilities. :o
Gotta gather all the data i can . :o