Skip to content
This repository has been archived by the owner on May 5, 2021. It is now read-only.

Android and PC Remotes: how do they work?

evanrich edited this page Mar 16, 2012 · 10 revisions

Android Remote

android screenshot android screenshot android screenshot

Windows Remote

wpf screenshot

As I'm not yet fully familiar with sending/receiving bytes over bluetooth, in .NET, or in java/android, I stuck with sending simple alpha characters that I knew the code on the Atmega328 could easily handle. In testing, I found that the easiest text to read on the Sure 3216 displays was Capital text, not lower case. Since I needed the entire capital alphabet, plus numbers and symbols, this left the lower case characters free for use. See below for how messages are constructed in the Android and .NET applications, and how the control board decrypts them.

Forming a message:

Each message consists of 3 control characters, the message to be displayed, and then a stop character which tells the controller to send the message to the display. The sequence goes like this:

repeat character + color character + speed character + message + End of Message character

The characters used are:
End of Message = "a"
repeat on = "b"
repeat off = "c"
Color green = "d"
Color Red = "e"
Color Orange = f"

Speed is controlled by the letters q through z, going from 10(fastest) to 100 (much slower)

If you want to send the message "HI MOM" in Orange, at the fastest setting, and not repeat, the message string would be constructed as such:

"cfqHI MOMa"

I know, looks confusing...but remember, on the other end, the ATMega processor knows to remove all of those control characters, so you never see them displayed. They simply set variables and then clear the buffer so it's ready to receive the next Serial byte, using a series of CASE statements.

Note: Even if repeat is not toggled on, the app sends "c" anyway, as it's a required parameter, and was easier to code then checking to see if the value was there or not. The reason for this was because the program strips the first 3 characters and the last 1 from every message before adding it to the history list in the Android app, and it would've been more work to check for variables.

Controller code:

in the void loop section, it starts reading upon establishing a connection to the bluetooth module:

if (Bluetooth.available())
 {  
inByte = Bluetooth.read();
switch (inByte){

It will start reading bytes, shifting the buffer one space

 default:
    // not a 'newline' character
    if (bufferPointer < bufferSize - 1)  // Leave room for a null terminator
      inputBuffer[bufferPointer++] = inByte; 

until it receives an "end of message" character, at which point the microcontroller is told to send the buffered message to the display:

case displaytext:            
    // 'newline' character
    inputBuffer[bufferPointer++] = '\0';
    dotmatrix.hscrolltext(0,inputBuffer,displaycolor, scrollspeed, 1, msgDirection);

Similarly, speed, color, etc are handled the same way:

case ten:    
  scrollspeed = 10;
  bufferPointer = 0;
  break;

 case Green: 
  displaycolor = GREEN;  //set color to Green
  bufferPointer = 0;
  break;
case Red: 
  displaycolor = RED;  //set color to Red
  bufferPointer = 0;
  break;   
case Orange: 
  displaycolor = ORANGE;  //set color to Orange
  bufferPointer = 0;
  break;