Displaying from serial problem

General MicroView Support area - You have questions, find your answers here.

Moderators: phalanx, Help@GeekAmmo, marcus@geekammo

Post Reply
bl00p
Posts: 1
Joined: Tue Sep 22, 2015 10:18 am

Displaying from serial problem

Post by bl00p » Thu Sep 24, 2015 8:13 pm

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!

scotta
Posts: 43
Joined: Thu Jul 24, 2014 1:31 pm
Location: Toronto, Canada

Re: Displaying from serial problem

Post by scotta » Fri Sep 25, 2015 5:32 am

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.

Post Reply