Help with displaying letters with SevenSeg.h library

Hi all, and thank you in advance. I am trying to display letters to a 2 digit 7 segment display using the SevenSeg.h library. I have the numbers displaying correctly with help and using: numberToDisplay=32(32 being a random #).
My issue is that I can't seem to send letters.
I have tried:
write("AA");
numberToDisplay= A;
and all sorts of newbie combinations in between.
When using numberToDisplay = 'A', it shows up as 65 which I understand is the same thing as "A" but I'm trying to get the letter. Two letters actually.
I read their documentation and cannot seem get this.
Any suggestions would be greatly appreciated.

Please post your code inside code tags, as explained in the first posts at the top of the forum. We can't guess how your examples work without seeing the whole thing.

My apologies, I thought it was just a command in SevenSeg.h library I didn't know. I'm using in it the Ardudroid app. Below is the code which works fine other than the fact i cannot get the letters to display.

#include <SevenSeg.h>

/*
PROJECT: ArduDroid
PROGRAMMER: Hazim Bitar (techbitar at gmail dot com)
DATE: Oct 31, 2013
FILE: ardudroid.ino
LICENSE: Public domain
*/

#define START_CMD_CHAR '*'
#define END_CMD_CHAR '#'
#define DIV_CMD_CHAR '|'
#define CMD_DIGITALWRITE 10
#define CMD_ANALOGWRITE 11
#define CMD_TEXT 12
#define CMD_READ_ARDUDROID 13
#define MAX_COMMAND 20  // max command number code. used for error checking.
#define MIN_COMMAND 10  // minimum command number code. used for error checking.
#define IN_STRING_LENGHT 40
#define MAX_ANALOGWRITE 255
#define PIN_HIGH 3
#define PIN_LOW 2

SevenSeg disp(2,3,4,5,6,7,8); // I Added this code to orginal Ardudroid program to display my digits
const int numOfDigits=2;
int digitPins[numOfDigits]={12,13};
int numberToDisplay;

String inText;

void setup() {
 Serial.begin(9600);
 Serial.println("ArduDroid 0.12 Alpha by TechBitar (2013)");
 Serial.flush();


 disp.setDigitPins(numOfDigits,digitPins); 
 disp.setCommonCathode();
 digitalWrite(2, LOW);
 digitalWrite(3, LOW);
 digitalWrite(4, LOW);
 digitalWrite(5, LOW);
 digitalWrite(6, LOW);
 digitalWrite(7, LOW);
 digitalWrite(8, LOW);


}

void loop()
{
 disp.write(numberToDisplay);

 Serial.flush();
 int ard_command = 0;
 int pin_num = 0;
 int pin_value = 0;
 pinMode(10,OUTPUT);
 digitalWrite(10, HIGH);
 char get_char = ' ';  //read serial

 // wait for incoming data
 if (Serial.available() < 1) return; // if serial empty, return to loop().

 // parse incoming command start flag
 get_char = Serial.read();
 if (get_char != START_CMD_CHAR) return; // if no command start flag, return to loop().

 // parse incoming command type
 ard_command = Serial.parseInt(); // read the command

 // parse incoming pin# and value 
 pin_num = Serial.parseInt(); // read the pin
 pin_value = Serial.parseInt();  // read the value

 // 1) GET TEXT COMMAND FROM ARDUDROID
 if (ard_command == CMD_TEXT){   
   inText =""; //clears variable for new input   
   while (Serial.available())  {
     char c = Serial.read();  //gets one byte from serial buffer
     delay(5);
     if (c == END_CMD_CHAR) { // if we the complete string has been read
       // add your code here
       break;
     }             
     else {
       if (c !=  DIV_CMD_CHAR) {
         inText += c;
         delay(5);
       }
     }
   }
 }

 // 2) GET digitalWrite DATA FROM ARDUDROID
 if (ard_command == CMD_DIGITALWRITE){ 
   if (pin_value == PIN_LOW) pin_value = LOW;
   else if (pin_value == PIN_HIGH) pin_value = HIGH;
   else return; // error in pin value. return.
   set_digitalwrite( pin_num,  pin_value);  // Uncomment this function if you wish to use
   return;  // return from start of loop()
 }

 // 3) GET analogWrite DATA FROM ARDUDROID
 if (ard_command == CMD_ANALOGWRITE) { 
   analogWrite(  pin_num, pin_value );
   // add your code here
   return;  // Done. return to loop();
 }

 // 4) SEND DATA TO ARDUDROID
 if (ard_command == CMD_READ_ARDUDROID) {
   // char send_to_android[] = "Place your text here." ;
   // Serial.println(send_to_android);   // Example: Sending text
   Serial.print(" Analog 0 = ");
   Serial.println(analogRead(A0));  // Example: Read and send Analog pin value to Arduino
   return;  // Done. return to loop();
 }
}

// 2a) select the requested pin# for DigitalWrite action
void set_digitalwrite(int pin_num, int pin_value)
{
 switch (pin_num) {


  // below (case 13) is where I want to display letters instead of numbers. numberToDisplay='A' doesn't send "A', it sends #65. 
 case 13:
    numberToDisplay = 'A'; // I actually need this to display two letters. Would it be written as ='A\A'; ? 
    break;
    
 case 12: // Unsed
  
  break;
    
  case 11: 
    pinMode(11, OUTPUT);
   digitalWrite(11, pin_value);
   break;
   
   case 10: 
    pinMode(10, OUTPUT);
   digitalWrite(10, pin_value);
   break;
   
 case 9:
   numberToDisplay= 0;
   break;
   
 case 8:
   numberToDisplay = 1;
   break;
    
 case 7:
   numberToDisplay = 7;        
   // add your code here
   break;
   
 case 6:
   numberToDisplay = 6;
   break;
   
 case 5:
   numberToDisplay = 5;   
   break;
   
 case 4:
   numberToDisplay = 4;
   break;
   
 case 3:
   numberToDisplay = 3;
   break;
   
 case 2:
   numberToDisplay = 2;
   break;     
   // default:
   // if nothing else matches, do the default
   // default is optional

 } 
}

The write function accepts different datatypes, including strings. But you always send it an int.

Again my apologies Aarg, I should have also said i'm new to Arduino and programming. I'm not exactly sure what you mean. I have the "int numberToDisplay" already defined. Does that just handle digits and not letters?

JDiz:
Again my apologies Aarg, I should have also said i'm new to Arduino and programming. I'm not exactly sure what you mean. I have the "int numberToDisplay" already defined. Does that just handle digits and not letters?

Yes. the write function works differently depending on what type of data you send to it. Here is what is available, copied from SevenSeg.h:

// High level functions for printing to display
    void write(long int);
    void write(int);
    void write(long int,int);
    void write(int, int);
    void write(char*);
    void write(String);
    void write(double);
    void write(double num, int point);

You should send a char*, but you'll have to consult the library documentation for details. When you do that, it would look something like write("AB").

If you want to write a letter (a character aka char) then don't save it as an int :wink: The write function sees it's an int and will just write the ascii value for that letter. If you send a char it will write the ascii character itself :wink: So make number to send a char numerToSend and for the numbers also use the ascii number (numberToSend = '1' instead of numerToSend = 1).

Also, you only check once for an available byte (one byte) in the serial buffer but you read more then one byte out of the buffer :wink: If you want to read more then one byte, check for more then one byte :wink:

Also, don't use delay to "fix" serial read :wink:

And why do you want to display a 1 when you have a 8??

Thank you for your time and patience on this. I did read up on that part of SevenSeg you referenced, I guess i just don't have the knowledge on how to apply it.
Where do I add "void write(char*);"?
I tried adding it under my "case 13" like this:

case 13: 
    void write(char*);
    write(AB);
    break;

this is the error I get:

: In function 'void set_digitalwrite(int, int)':
: error: 'AB' was not declared in this scope

You don't write void write(char*);, it's already in the library.

If you want to write a char, DON'T put it in a int :wink:

Doing

disp.write('A');

will just work fine. So will

char myChar;
myChar = 'A';
disp.write(myChar);

So if you want to write a char, don't write a int (because that's what you do by numberToDisplay = 'A' because numberToDisplay is defined as a int).

Thank you septillion! Gonna try that here in sec and repost the results. Thank you for your help you guys!

Septillion, Just tried adding:

case 13:
  disp.write('A');
  break;

It only flickers on for few millisecs when i press button 13 on the Ardudroid app then goes off when i release my finger. It doesnt stay on but it flickers on enough to read that is still displaying #65 instead of "A".

Same happened when I tried the other version you posted with the:

char myChar;
myChar = 'A';
disp.write(myChar);

changing

numberToDisplay = '1';

into

char numerToSend = '1';

i get the following error

error: jump to case label [-fpermissive]
error:   crosses initialization of 'char numerToDisplay'

Go back to the basics! Start by creating a new sketch and only write/copy the part that's needed to display something.

Also, which SevenSeg library do you use? If I Google I find this one but at first glance it looks like you use it different then how you use it....

What i'm trying to do with this project is that I have a answering machine I gutted for a stage prop.
The answering machine reads 1 on its display. when a fake call comes in i press button 13 on ardudroid to have it display An (answer)...i blink it on and off a few times, then press button 2 on ardudroid to cahnge the display to 2 (as in a new message is there) my only work around to this due to my lack of programming experience was to change in the SevenSeg library the #9 to light p as a "A" and the number 8 to light up as "n", but now i can't use the number 9 or 8. I dont really need them for this gag but would love a better understanding how to correctly code this.

I believe i'm using the old SevenSeg.h library under the one you linked to. I will remove the old one and include that newer SevenSeg/+ version. Thanks Septillion. Crossing fingers :slight_smile: