Skip to content

11. Input devices

This week we had following objectives

  • individual assignment: measure something: add a sensor to a microcontroller board that you have designed and read it
  • group assignment:probe an input device’s analog levels and digital signals

Getting Started

Background

In week9 i already started looking into what i need for final project and you can find out more details on checking out these pages.

Key things i needed for the project

  • Atmgea328p will be the final microcontroller i will be using for my project. There are good reasons for it. a) This is the main microcontroller that is used in Arduino and b) I have various good resources available in fab lab and on internet. Famous one i like are as below satshakit and Indoor Aquaponics by Guillaume Teyssié

  • Raspberry pi : Food computer brain is based on Python. Lastest version 3.0 of Food computer brain is hosted on google cloud platform and uses both raspberry pi and Beaglebones. The 300 dollar food computer MVP brain is all based on Raspberry Pi only. For my project i want to use Raspberry pi and my own satshakit(arduino) fabricated board. This would add a new enhancement to food computer by adding an easily fabricated board in fablabs.

For input week as assignment key objective was to read data from a sensor. In lecture Neil explained a lot of sensors and sample videos and programs on how to use these sensors. But for my final project i was unable to find any examples. But same is very well explained on Guillaume Teyssié page. And i used this page to learn more about the sensors. I started with understanding following key sensors for this week.

  • DHT22 - Temprature and Humidity Sensor Module link

  • DS18B20 Water Proof Temperature Probe link

Spiral Development Approach for Upcoming Weeks

As the final microcontroller i want to use in my project is Atmega. This decision allows me to test and prototype my code on famous rapid prototyping microcontroller board Arduino. So before i can fabricate my own board using satshakit this help me do rapid prototyping without spending time on milling and also insights on how to design my board and that would be portable on satshakit.This is the approach i will be using in for all upcoming weeks. Test solution on arduino, learn and design my own board based on satshakit to create final PCB.

Picture showcasing Satshakit and Arduino Pin mapping and how FabISp can be used to Program the same.

Arduino and DHT22 - Temprature and Humidity Sensor Testing

Basically to hook this sensor to arduino we need VCC, GND and Signal pin connected to Arduino digital PWM pins.

I found a good article on circuitbasics which i followed and this is the final outcome. I was successfully able to read the sensor data on Arduino.

Setting Up Raspberry Pi

I wanted to use this week to setup my raspberry pi based on the instructions shared at 300 dollar food computer MVP. The setup of raspberry pi is very well documented on attached pdf. I simply followed the steps mentioned and was able to setup the Raspberry Pi Operating system.

To setup the raspberry pi these are the pre-requisites you need

  • Raspberry pi
  • Keyboard
  • Mouse
  • HDMI cable
  • Display
  • Wi-fi connection
  • 32 GB SD Card

Screenshots for my Raspberry pi Operating System Setup

Understading Food Computer Brain

MVP food computer don’t go into details of how food computer brain works so i decided to actually setup the latest food computer software to understand how it all works. Food computer 3.0 has two versions of software one that run locally and another on Cloud. There are very good introductory videos on the GitHub that explains different part of software architecture. So i spent some time on understanding the overall software architecture of Food Computer

Key learnings

  • Main interface for food computer is I2C to speak to sensor and actuators. I was not clear on I2C so i googled and found following good article on it.Next i planned to test it out. What i did next was to setup a I2C communication between Raspberry Pi and Arduino. I followed following article and below is the outcome.

  • Postgres is the database that is used to store the data from sensors
  • MQTT is the protocol used to transfer data from IoT device to google cloud
  • Django is a python frameowork that is used to create web app and application
  • It uses State Machine architecture pattern

Group work - Input Devices

You can find more details on our Lab Group page. This week our group assignment was to probe an input device’s analog levels and digital signals.

Understanding Oscilloscopes

While working with electronics, for debugging and testing behavior, we need to understand the circuits on signal level, which multimeters fails to do. In this case Oscilloscopes comes into picture. A digital oscilloscope measures the signal, and then converts that measurement into a digital format using an ADC converter, after which the data measured is depicted as a digital waveform representation. From this representation various paramters can be evaluated. In our lab we got Scientific SMO1102E and Keysight DSO1052B Oscilloscopes.

Key Capabilities

  • Bandwidth = 50 MHz
  • Channels = 2
  • Max Memory Depth = 16 kpts
  • Max Sample Rate = 1 GSa/s
  • Display Size = 5.7 inch
  • ADC Bits = 8 bits
  • USB storage, RS232C and J45 interface
  • Multi-waveforms math, FFT Function
  • Built-in delay sweep function
  • Waveform Record and Recall, Trigger Mode for Edge, Video, Pulse Width, Slope and Alternate

Caliberating the Probes

Before using the oscilloscope we needed to caliberate the probe. Our instructor Rahul walked us through the process.

Measuring Digital Signals

  • First we tested out the crystal on an Arduino UNO, we connected the probes to the crystal of Ardunio Uno which showed a frequency of 16 MHz.

  • We then uploaded Blink code on the UNO board and we observed the pulse signal.

Measuring Analog Signals

For measuring the analog signals, We connected both the terminals fo the motos with the probes of the DSO and then we rotated the motor shaft manually.

Observations

  • On the DSO Screen, It may be noticed that digital pulses with a time gap of 1 seconds were observed with peak value of voltage of 5V.
  • Also it was obeserved that the pulses were smooth, as we caliberated the probes earlier as showcased in video
  • Analog signal was clearly visualized on the DSO Screen.(An Analog signal is any continous signal for which the time varying feature (variable) of the signal is a representation of some other time varying signal i.e analogous to another time varying signal, This is also the reason why wave form is rising up and down with time.)
  • DSO was measuring voltage w.r.t Time and A peak voltage of about +10V was observed.
  • When the motor shaft direction is reversed the signal also changes the ploarity and a reverse peak voltage of about -8V was observed

Designing the PCB for Final Project

Based on my project requirement i am actually looking to design a single board at the end of fab lab project. So each week planning to enhance the same board with new skills. For this week focus has been reading data from sensor. So i planned to use DHT22 - Temprature and Humidity Sensor with ATMEGA microcontroller. This week i designed the board in KiCad and added AVRISP , FTDI headers and header pins for Output device OLED display too in this week itself. Again this was a good exercise for me to understand how i will interface various devices for food computer. The challenge i saw that the final board i am planning to use satsha kit but instead of using the design that was already their i started re-inventing the wheel. So i dropped the idea of doing everything in KiCad.But here is what i have designed in KiCad.

Trying Design in KiCad

Trying Design in Eagle

Once i was clear on what i needed i started working on my final project board straight away using Satsha Kit

I used eagle for this, reason being the satsha kit is designed in eagle and it was easier to modify this instead of designing it from scratch. So i downloaded satsha kit and based on my final project i decided to use I2C protocol and added NodeMCU too. You can find more details in Week 14 Networking and Communications and Week 16 Application and Interfaces how this design is a key integral part of my final project. I am planning to use NodeMCU which will take instruction from Alexa (AWS Voice Enabled Speaker) to control various relays that would turn on LED lights, Fan, Water Pump etc. for food computer using Voice command.

Milling and Soldering the Board

Week5 Electronics Production cover milling and soldering process in detail. So i am not covering the same in this week again. But you can refer the details in week 5 for using SRM, FAB MOD and soldering. Below are the hero snapshot for the input and output board aligned to my final project. I only soldered what was needed for input and output week.

Programming the Board

I first tested out the Blink code on my board to test out the board is working fine or not. Its a free sketch that is available in Arduino IDE. Also you can learn more about programming microcontroller in Embedded Programming Week 9 . Again i am using FTDI, AVR programmer and Arduino IDE to program my board.

Below is the Arduino code for reading data from sensor for Input week. And you can check code for Output week in Output Week 12

#include <dht.h>

dht DHT;

void setup() {

  Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:

  int chk = DHT.read11(8);
  Serial.print("Temperature = ");
  Serial.println(DHT.temperature);
  Serial.print("Humidity=");
  Serial.println(DHT.humidity);
  delay(2000);

}

Final Outcome

Here is the Snapshot of final outcome.

Overall Learning

  • Overall this week i have made significant progress on my project electronics
  • I leart how to read data from a DHT22 sensor and display it on serial port
  • I learnt how to setup raspberry pi
  • I spent good amount of my time on food computer brain to understand different parts of software
  • Happy with the board as it takes out major chunk of my electronics design and help me focus on other aspects of my project
  • I learnt about using DSO and how it can be used to debug signals