Page 1 of 1

Displaying from serial problem

Posted: Thu Sep 24, 2015 8:13 pm
by bl00p
Hello everyone,

I was just given a MicroView to play around with and I decided to build a temperature sensor. I'm using a raspberry pi to hook up the sensor too and python using pyserial to write the script to read the sensor and send it out to the MicroView. I can provide the python code if needed. My problem is with displaying it on the MicroView. My code as it stands now for some reason only displays one character at a time, for instance if the temperature is 86.1 the MicroView displays the 8 pauses then erases the 8 and displays the 6 pauses and so on and so forth. Here is the code for reference.
Code: Select all
#include <MicroView.h>

void setup() {
  uView.begin();
  uView.clear(PAGE);
  Serial.begin(9600);
}

void loop() {
  char a;
  if (Serial.available()) {
    a = Serial.read();
    uView.setFontType(1); 
    uView.setCursor(0,16);
    uView.print(a);
    uView.display();
  }
delay(2000);
}
If I remove the setCursor function, it'll display the temperature (in full) and when it loops back it'll display the next temperature reading underneath the first one and so on and so forth. I added the setCursor function because I want the temperature to display in one spot and when it loops back replace the old one with the new reading but it doesn't seem to work. Any help would be very much appreciated. Thanks!

Re: Displaying from serial problem

Posted: Fri Sep 25, 2015 5:32 am
by scotta
You're only reading one character at a time. You should change char a to a string (or array) and then use Serial.readString(), instead of Serial.read(), to get all the characters sent. Instead of Serial.readString(), you could also consider using Serial.readStringUntil() or Serial.readBytesUntil() if one of them is more suitable.

You may also wish to put a uView.clear() before the uView.setCursor() or use some other means to clear the previous reading on the display.