I'm in love with your OLED breakouts! I'm using the SSD1306 v2.1 and really want to use it with the MLX90614 to reverse engineer this http://www.radioshack.com/product/index ... Id=4288088
Ive got the test running fine I was just hoping someone could point me in the right direction to learn how to write this serial output to the OLED.
Thanks!
Write to OLED
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88088
- Joined: Sat Feb 07, 2009 10:11 am
Re: Write to OLED
You can call write() print() and println() just like with a serial port. Because it is a graphical display, you have to set the text size, color and cursor position first. This is from the example code in the library: https://github.com/adafruit/Adafruit_SSD1306
Code: Select all
void testdrawchar(void) {
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
for (uint8_t i=0; i < 168; i++) {
if (i == '\n') continue;
display.write(i);
if ((i > 0) && (i % 21 == 0))
display.println();
}
display.display();
}
- DisruptItYourself
- Posts: 193
- Joined: Mon Sep 23, 2013 6:58 pm
Re: Write to OLED
As I move everything over to an Arduino Micro Im having some trouble. I'm not getting a value from the sensor MLX90614. I'm simply getting the max values:
Ambient = 1037.55*C Object = 1037.55*C
Ambient = 1899.59*F Object = 1899.59*F
...which I believe the sketch kicks out if its not getting anything from the sensor. I've tried different jumper wires I don't know what could be wrong.
Ambient = 1037.55*C Object = 1037.55*C
Ambient = 1899.59*F Object = 1899.59*F
...which I believe the sketch kicks out if its not getting anything from the sensor. I've tried different jumper wires I don't know what could be wrong.
- adafruit_support_bill
- Posts: 88088
- Joined: Sat Feb 07, 2009 10:11 am
Re: Write to OLED
How do you have it wired up? I2C is on different pins on the Micro.
http://arduino.cc/en/Main/arduinoBoardMicro
http://arduino.cc/en/Main/arduinoBoardMicro
- DisruptItYourself
- Posts: 193
- Joined: Mon Sep 23, 2013 6:58 pm
Re: Write to OLED
Ok I'm dumb but I guess I'm learning. I realized that I was just connecting the SCL and SDA pins to the same analog 4 and 5 pins on the Micro when it should have been digital 2 and 3!
Now I just need to improve my programming ability enough to wrap my head around displaying the temperature on the OLED. Wish me luck! haha
Now I just need to improve my programming ability enough to wrap my head around displaying the temperature on the OLED. Wish me luck! haha
- DisruptItYourself
- Posts: 193
- Joined: Mon Sep 23, 2013 6:58 pm
Re: Write to OLED
ok so this is my code:
Its working really well but can you explain to me how I could modify it to only read/write the temperature when I press a button?
Code: Select all
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_MLX90614.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
// If using software SPI (the default case):
#define OLED_MOSI 9
#define OLED_CLK 10
#define OLED_DC 11
#define OLED_CS 12
#define OLED_RESET 13
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
#define XPOS 0
#define YPOS 1
#define DELTAY 2
void setup() {
Serial.begin(9600);
Serial.println("Adafruit MLX90614 test");
mlx.begin();
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC);
// init done
}
void loop() {
// write temperature
temperatureDisplay();
delay(2000);
display.clearDisplay();
display.display();
//serial
Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC());
Serial.print("*C\tObject = "); Serial.print(mlx.readObjectTempC()); Serial.println("*C");
Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempF());
Serial.print("*F\tObject = "); Serial.print(mlx.readObjectTempF()); Serial.println("*F");
Serial.println();
delay(500);
}
void temperatureDisplay(void) {
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(5,0);
display.clearDisplay();
display.println("Temperature:");
display.println(mlx.readObjectTempF());
display.display();
}
- adafruit_support_bill
- Posts: 88088
- Joined: Sat Feb 07, 2009 10:11 am
Re: Write to OLED
First you need to get a button connected. Lesson 6 shows how to connect buttons write code to control things with them: http://learn.adafruit.com/adafruit-ardu ... tal-inputs
- DisruptItYourself
- Posts: 193
- Joined: Mon Sep 23, 2013 6:58 pm
Re: Write to OLED
Cool! This is working pretty well!
Code: Select all
//This code belongs to Andrew Stott and is based on code
//provided by Adafruit industried under an open source license.
//Likewise this code is open sorce and can be used and modified.
//I simply ask that you let me know so that we can learn together.
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_MLX90614.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
// If using software SPI (the default case):
#define OLED_MOSI 9
#define OLED_CLK 10
#define OLED_DC 11
#define OLED_CS 12
#define OLED_RESET 13
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
#define XPOS 0
#define YPOS 1
#define DELTAY 2
int buttonA = 5;
void setup()
{
Serial.begin(9600);
Serial.println("Adafruit MLX90614 test");
pinMode(buttonA, INPUT_PULLUP);
mlx.begin();
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC);
// init done
}
void loop()
{
{
if (digitalRead(buttonA) == LOW)
{
// write temperature
temperatureDisplay();
delay(2000);
display.clearDisplay();
display.display();
}
if (digitalRead(buttonA) == HIGH)
{
display.println("Press button for temperature");
}
}
}
void temperatureDisplay(void) {
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.clearDisplay();
display.println("Temp");
display.println(mlx.readObjectTempF()); display.print((char)247); display.println("F");
display.display();
}
Please be positive and constructive with your questions and comments.