7 segment serial display with TTL serial need help

Hello,

i try to show random numers on this 7 segment display (http://www.sparkfun.com/commerce/product_info.php?products_id=9230)
can anyone helpt with this ?

i think i can use this as a basis code ?

void setup() { //c/c++ is case sensitive Void is not the same as void
Serial.begin(9600);
pinMode(11, OUTPUT);
}

void loop() {
Serial.print(0x02); //use print instead of write
Serial.print(0x03);
Serial.print(0x04);
Serial.print(0x05);
}

i really hope someone can help me with this

(enteng)

http://arduino.cc/en/Reference/RandomSeed
http://arduino.cc/en/Reference/Random
(Not sure what pin 11 is doing)

thanks for the reply.
i tried to integrate it in a program that works for me, but now still 0000 is shown

it would be great if you could help me.

or is it about that analog input pin 0 is not connected?
do i really need to connect it or is there some other problem?
in the serial monitor window it is doing what i want it to do, but not at the display

this is my code now:

// library
#include <SoftwareSerial.h>

// Pin for 7 segment display
#define rxPin 2
#define txPin 3
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);

long randNumber;

void setup(){
Serial.begin(9600);

// define pin modes for tx, rx, led pins:
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);

// if analog input pin 0 is unconnected, random analog
// noise will cause the call to randomSeed() to generate
// different seed numbers each time the sketch runs.
// randomSeed() will then shuffle the random function.
randomSeed(analogRead(0));
}

void loop() {
// print a random number from 0 to 9999
randNumber = random(9999);
Serial.println(randNumber);

delay(1000);
}

Maybe you should start to use 'mySerial'

ah yes. thanks a lot!

now the problem is that not only numbers are shown...

I think you need to exercise your powers of description a little more.

it's all new to me. i'm just trying.

so you mean it have something to do with the analog port 0 ?
or do you mean what i say is not so clear ?

We can't see what you can see, or what tests you've applied to make sure your display does what you expect.
So, you need to tell us.

ah ok.

well. i changed it like this:

// library
#include <SoftwareSerial.h>

// Pin for 7 segment display
#define rxPin 2
#define txPin 3
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);

long randNumber;

void setup(){
mySerial.begin(9600);

// define pin modes for tx, rx, led pins:
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);

// if analog input pin 0 is unconnected, random analog
// noise will cause the call to randomSeed() to generate
// different seed numbers each time the sketch runs.
// randomSeed() will then shuffle the random function.
randomSeed(analogRead(0));
}

void loop() {
// print a random number from 0 to 9999
randNumber = random(10000);
mySerial.println(randNumber);

delay(1000);
}

and now the display is working, but i does not only give numbers, but also other characters.

and it works perfect in the serial monitor if i put it like this (then i see numbers between 0 and 10000 in the serial monitor, but not at my 7 segment display)

// library
#include <SoftwareSerial.h>

// Pin for 7 segment display
#define rxPin 2
#define txPin 3
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);

long randNumber;

void setup(){
Serial.begin(9600);

// define pin modes for tx, rx, led pins:
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);

// if analog input pin 0 is unconnected, random analog
// noise will cause the call to randomSeed() to generate
// different seed numbers each time the sketch runs.
// randomSeed() will then shuffle the random function.
randomSeed(analogRead(0));
}

void loop() {
// print a random number from 0 to 9999
randNumber = random(10000);
Serial.println(randNumber);

delay(1000);
}

what is going wrong ?
i hope i'm clear now.
and thanks for helping!

I'm still not seeing your test program, that simply displays a fixed, known number on your seven segment display.
Or a simple count that increments every second.

This

NOTE: You must always send your data in 4-byte packets

is at the top of the first page of the reference manual for the display.

There are several problems with your code. First, SoftwareSerial is obsolete, and has been for years. You should be using NewSoftSerial, instead.

Second, you have told the software serial instance that the pins whose numbers are defined in txPin and rxPin are it's to do with as it sees fit. Yet, you set pinMode on them. Don't do that.

It isn't clear what the software serial instance is driving, but sending the extra carriage return/line feed to a 7 segment serial display is not likely to produce meaningful output on the display. Do not use println() to write to a 7 segment display.

You can't Serial.println(randNumber); to that display, try (where mySerial is an NSS instance)

mySerial.print('1');
mySerial.print('2');
mySerial.print('3');
mySerial.print('4');

I think it will interpret ASCII chars correctly.

mySerial.print(1);
mySerial.print(2);
mySerial.print(3);
mySerial.print(4);

Should also work unless they've changed the software recently.

If they work then you have to convert randNumber to 4 bytes.


Rob

thanks!
ok this is kinda funny, because maybe it's not by the rules and stuff, but now it works.

// library
#include <SoftwareSerial.h>

// Pin for 7 segment display
#define rxPin 2
#define txPin 3
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);

long randNumber;

void setup(){
  mySerial.begin(9600);

 // define pin modes for tx, rx, led pins:
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  
// randomSeed(analogRead(0));
}

void loop() {
  // print a random number from 0 to 9999
 randNumber = random(10000);
  mySerial.print(randNumber);  

  delay(500);
}

Because a long is four bytes and randNumber is a long. You stopped sending the CR/LF by using print instead of println so now you are sending 4 bytes as per the display requirements.

So yes it's "working", but I bet the numbers being displayed are not correct because you are using random and therefore don't know what should be displayed anyway.

Try

void loop() {
static long x = 0;

  mySerial.print(x++);  

  delay(500);
}

and let us know what the results are.


Rob

that's what i said, it does what i wanted it to do, so i'm happy.

ok i tried what you said.

yes i see logic in that.
it starts with only one segment at the time is counting 2,4,6,8 and others 1,3,5, ect.
after a while i can't see the logic anymore and then it looks like the result i had with my code.

interesting

That's as I figured.

Anyway you have what you need for now, if you ever want predictable numbers come talk to us again :slight_smile:


Rob