Hi Everyone,
I am looking for some help on a small project I’m working on with the photon. I’m using a moisture sensor from sparkfun, and a oled screen. I’d like to have the output on the oled screen be a “Moisture Content %”.
At this time I am just pulling the A0 reading, but not sure how to convert that into a MC% reading.
// This #include statement was automatically added by the Particle IDE.
#include "SparkFunMicroOLED/SparkFunMicroOLED.h"
/******************************************************************************
Micro-OLED-Shield-Example.ino
SparkFun Micro OLED Library Hello World Example
Jim Lindblom @ SparkFun Electronics
Original Creation Date: June 22, 2015
This sketch prints a friendly, recognizable logo on the OLED Shield, then
goes on to demo the Micro OLED library's functionality drawing pixels,
lines, shapes, and text.
Hardware Connections:
This sketch was written specifically for the Photon Micro OLED Shield,
which does all the wiring for you. If you have a Micro OLED breakout,
use the following hardware setup:
MicroOLED ------------- Photon
GND ------------------- GND
VDD ------------------- 3.3V (VCC)
D1/MOSI ----------------- A5 (don't change)
D0/SCK ------------------ A3 (don't change)
D2
D/C ------------------- D6 (can be any digital pin)
RST ------------------- D7 (can be any digital pin)
CS ------------------- A2 (can be any digital pin)
Development environment specifics:
IDE: Particle Build
Hardware Platform: Particle Photon
SparkFun Photon Micro OLED Shield
This code is beerware; if you see me (or any other SparkFun
employee) at the local, and you've found our code helpful,
please buy us a round!
Distributed as-is; no warranty is given.
*******************************************************************************/
#include "math.h"
//////////////////////////////////
// MicroOLED Object Declaration //
//////////////////////////////////
// Declare a MicroOLED object. If no parameters are supplied, default pins are
// used, which will work for the Photon Micro OLED Shield (RST=D7, DC=D6, CS=A2)
MicroOLED oled;
//MicroOLED oled(MODE_I2C, D7, 0); // Example I2C declaration RST=D7, DC=LOW (0)
//SYSTEM_MODE(MANUAL);
void setup()
{
Serial.begin(9600);
oled.begin(); // Initialize the OLED
oled.clear(ALL); // Clear the display's internal memory
oled.display(); // Display what's in the buffer (splashscreen)
delay(1000); // Delay 1000 ms
randomSeed(analogRead(A0) + analogRead(A1));
}
void loop()
{
readmoisture(); // read and dispaly moisture
}
void readmoisture()
{
oled.clear(PAGE); // Clear the display
oled.setCursor(0, 0); // Set cursor to top-left
oled.setFontType(1); // Smallest font
oled.print("M%:"); // Print "Moisture"
oled.setFontType(1); // 7-segment font
oled.print(analogRead(A0)); // Print a0 reading
oled.display();
delay(1000);
}