12. Output devices

Highlights

Group Assignment

1. Setup

The OLED displayed temperature and humidity data. Of the 4 pins GND, VCC, SCL and SDA the multimeter was connected inbetween the VCC wire connection. The current from source passed through multimeter and reached OLED. Here, the multimeter displayed the value of current 2.59 milli Ampere.

2. Calculations

Volatge supplied to OLED from the source=5V
Current reading in multimeter=2.59mA
Power = voltage x current
Power= 5x2.59 mAV
Power=12.95 milliwatt

Individual Assignment

This week’s assignemnt is continuation of Week 11- Input Device for me. I have given connections for OLED in input device main board.The steps, processes and learnings from reading Atmega 328p Datasheet, schematic and board design in Eagle, milling on SRM20 and soldering of PCB is all docuemnted last week.

Code

#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display(4);
#include <Adafruit_GFX.h>
#include<SoftwareSerial.h>

SoftwareSerial mySerial(0,1);

// OLED display TWI address
#define OLED_ADDR   0x3C
#define ONE_WIRE_BUS 5
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup()

{  
 // Start up the library 
 sensors.begin();

   // initialize and clear display
      display.begin(SSD1306_SWITCHCAPVCC, 0x3C);

  display.clearDisplay();
  display.display();

  // display a pixel in each corner of the screen
  display.drawPixel(0, 0, WHITE);
  display.drawPixel(127, 0, WHITE);
  display.drawPixel(0, 63, WHITE);
  display.drawPixel(127, 63, WHITE);

  // display a line of text
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(27,30);
  display.print("Hello, world!");

  // update display with all of the above graphics
  display.display();

    }



void loop(){
 // call sensors.requestTemperatures() to issue a global temperature 
 // request to all devices on the bus 
/********************************************************************/ 
sensors.requestTemperatures(); // Send the command to get temperature readings  
  float t = sensors.getTempCByIndex(0);
  mySerial.print("Temperature is: ");
  mySerial.println(t); // Why "byIndex"?
// Serial.println(sensors.getTempCByIndex(0));
   // You can have more than one DS18B20 on the same bus.  
   // 0 refers to the first IC on the wire 
  //delay(4000); 
/********************************************************************/
  float u = sensors.getTempCByIndex(1);
  float d = ((17.502*t)/(240.97+t)); // Equation for Humidity
  float e = 2.7183;
  float g = 6.112*(pow(e,d));
  float j = ((17.502*u)/(240.97+u));
  float k = 2.7183;
  float m = 6.112*(pow(k,j));
  float n = (m-(0.6687*(1+0.00115*u)*(t-u)))/g*100; //Humidity upto 2 digit

 // put your main code here, to run repeatedly:
  }

Code Explaination

1. OLED is 0.96-inch display with 128×64 pixels.

2. The model I have used has only four pins and communicates with the Arduino using I2C communication protocol.

3. To control the OLED display added the Adafruit_SSD1306.h, Adafruit_GFX.h libraries.

4. Further, OneWire.h, DallasTemperature.h, Wire.h,SoftwareSerial.h have been included for digital thermometer to read and send temperature.

5. Here’s some functions that the OLED display library will use to write, text or draw simple graphics.
display.clearDisplay() – all pixels are off
display.drawPixel(x,y, color) – plot a pixel in the x,y coordinates
display.setTextSize(n) – set the font size, supports sizes from 1 to 8
display.setCursor(x,y) – set the coordinates to start writing text
display.print(“message”) – print the characters at location x,y
display.display() – call this method for the changes to make effect

Uploading programme:

1. Programmer: I used my Fab ISP made in Electronics Production weekly project to programme the main board. Selected “USBtinyISP” as programmer. 2. Board: THe microcontroller soldered is “ATmega 328p”. Added ATmega board library and insatlled it from board manager.
3. Processor: Specifically selected “ATmega 328p” processor. 4. Verify: With all these settings selected under tools section, compiled the Arduino code. 5. Uploading: WIth setup Fab ISP connected to laptop and the main board uploaded the code successfully.

Readings on OLED:

The picture and video below shows temperature and humidity data on OLED.

Arduino code available here
Board design and rml files available here