Go Down

Topic: Use of μ (mu) character on display? (Read 259 times) previous topic - next topic

approvedcargo91

Hi All,

   I am currently working on a sensor setup that outputs PM concentration, temperature, and relative humidity to an 0.96" Blue/Yellow OLED display (as well as to a Bluetooth terminal, but don't worry about that). My question is about the characters that can be displayed on this screen. I have a measurement with the units μg/m^3 that is printed to the screen. However, when I tried to print this to my display, the μ displayed incorrectly. Everything else displays as intended. I did a little research into the topic online and found the Adafruit GFX library; however, this seems mostly related to drawing point and line, etc. graphics. Is there a library I can download or modify to allow the use of μ? I've pasted my entire code down below in accordance with forum rules. I print all my values to the display at the very bottom of the code.
Code: [Select]
//include necessary libraries
#include <dht.h>
#include <Adafruit_ssd1306syp.h>
#include <SoftwareSerial.h>

dht DHT;
//pin and sensor parameter definitions
#define humiGr 5 //humiture ground digital 5
#define humiVCC 6 //humiture power digital 6
#define DHT11_PIN 7 //humiture digital 7
#define tempGr A0 //thermistor ground analog 0
#define tempVCC A1 //thermistor power analog 1
#define analogPin A2 //thermistor analog 2
#define beta 4090 //beta of thermistor
#define resistance 10 //pull-down resistor value
#define SDA_PIN 10 //digital 10
#define SCL_PIN 9 //digital 9
Adafruit_ssd1306syp display(SDA_PIN,SCL_PIN);

//PM Setup
int measurePin = 6; //wire 5 to analog 6
int ledPower = 12; //wire 2 to digital 12
int samplingTime = 280;
int deltaTime = 40;
int sleepTime = 9680;
double voMeasured = 0;
double calcVoltage = 0;
double dustDensity = 0;

//Smoothing Temp Setup
const int numReadings = 10;
double readings1[numReadings];
int index1 = 0;
double total1 = 0;
double average1 = 0;

//Smoothing PM Setup
double readings2[numReadings];
int index2 = 0;
double total2 = 0;
double average2 = 0;

//Smoothing Hum Setup
double readings3[numReadings];
int index3 = 0;
double total3 = 0;
double average3 = 0;

SoftwareSerial BT(3,11);
int count = 0;

void setup() {
  count = 0;
  Serial.begin(9600);
  BT.begin(9600);
  display.initialize();
  pinMode(ledPower,OUTPUT);
  for (int thisReading1 = 0; thisReading1 < numReadings; thisReading1++) {
  readings1[thisReading1] = 0;
  }
  for (int thisReading2 = 0; thisReading2 < numReadings; thisReading2++) {
  readings2[thisReading2] = 0;
  }
  for (int thisReading3 = 0; thisReading3 < numReadings; thisReading3++) {
  readings3[thisReading3] = 0;
  }
  analogWrite(humiGr,0); // effectively makes humiGr a ground pin
  analogWrite(humiVCC,255); // effectively makes humiVCC a 5V pin
  analogWrite(tempGr,0); // effectively makes tempGr a ground pin
  analogWrite(tempVCC,255); // effectively makes tempVCC a 5V pin
  /* The above four lines allow the humiture and thermistor to be
  plugged in right next to the Arduino, decreasing operating size. */
}

void loop() {     
  // PM Sensor Reading
  digitalWrite(ledPower,LOW); // power on the LED
  delayMicroseconds(samplingTime);
 
  long voMeasured = analogRead(measurePin); // read the pin value

  if (voMeasured <= (0.1 * 1024) / (5.0 * 0.17)) {
  delayMicroseconds(deltaTime);
  digitalWrite(ledPower,HIGH); // turn the LED off
  delayMicroseconds(sleepTime);
  dustDensity = 0;
  }
  else {
  delayMicroseconds(deltaTime);
  digitalWrite(ledPower,HIGH); // turn the LED off
  delayMicroseconds(sleepTime);
  calcVoltage = voMeasured * (5.0 / 1024);
  dustDensity = 0.17 * calcVoltage - 0.1;
  }
  //^^Sets negative values to zero

  // read thermistor data
  long a = 1024 - analogRead(analogPin);

  // Read humiture sensor data
  int chk = DHT.read11(DHT11_PIN);

  //Smoothing Loops
  //Temp
  total1 = total1 - readings1[index1];
  readings1[index1] = a;
  total1 = total1 + readings1[index1];
  index1 = index1 + 1;
  if (index1 >= numReadings) {
    index1 = 0;
  }
  average1 = total1 / numReadings;
 
  //PM
  total2 = total2 - readings2[index2];
  readings2[index2] = dustDensity;
  total2 = total2 + readings2[index2];
  index2 = index2 + 1;
  if (index2 >= numReadings) {
    index2 = 0;
  }
  average2 = total2 / numReadings;

  //Hum
  total3 = total3 - readings3[index3];
  readings3[index3] = DHT.humidity;
  total3 = total3 + readings3[index3];
  index3 = index3 + 1;
  if (index3 >= numReadings) {
    index3 = 0;
  }
  average3 = total3 / numReadings;
     
  //temperature formula
  float tempC = beta /(log((((1025.0 * 10) / average1) - 10) / 10) + (beta / 298.0)) - 273.0;
  float tempF = (tempC * 9 / 5) + 32.0;
 
  // Display data
  display.setTextSize(1);
  display.setTextColor(0xFFE0);
  display.setCursor(0,0);
  display.print("PM:");
  display.setTextSize(2);
  display.print(average2*1000, 3);
  display.setTextSize(1);
  display.println("μg/m^3");
  display.println("Temperature: ");
  display.setTextSize(2);
  Serial.print("Count before: ");
  Serial.println(count);
  if (count < 2) {
    display.print(tempC);
    display.setTextSize(1);
    display.print(" o");
    display.setTextSize(2);
    display.println("C");
  }
  else if (count > 1) {
    display.print(tempF);
    display.setTextSize(1);
    display.print(" o");
    display.setTextSize(2);
    display.println("F");
    if (count == 3) {
      count = -1;
    }
  }
  Serial.print("Count after: ");
  Serial.println(count);
  count = count + 1;
  display.setTextSize(1);
  display.println("Relative Humidity:");
  display.setTextSize(2);
  display.print(average3,1);
  display.println(" %");
  /*display.println("Dust Density:");
  display.print(average2, 4);
  display.println(" mg/m^3");
  display.println("Temperature: ");
  display.print(tempC);
  display.print(" C\n");
  display.print(tempF);
  display.print(" F\n"); 
  display.println("Relative Humidity:");
  display.print(average3,1);
  display.println(" %");*/
  if (tempC > 20) {
    //if (BT.available()) {
      //a = (BT.read());
      //if (a == 'A') {
        BT.print(average2, 4);
        BT.print(" ");
        BT.print(tempC);
        BT.print(" ");
        BT.print(tempF);
        BT.print(" "); 
        BT.println(average3,1); 
      //}
    //}
  }
  display.update();
  delay(500);
  display.clear();
}

AWOL

If your font doesn't include a mu, just use a lower case u.
Or modify the font.
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

approvedcargo91

I didn't really think of using a lowercase u  :smiley-roll-sweat:. I'm not exactly the brightest. Thanks for providing a simple solution! Much appreciated.

Go Up