Ciao a tutti ho acquistato da poco il nuovo 7segment display della Sparkfun.
Link:
https://www.sparkfun.com/products/11442La mia intenzione era quella di visualizzare sul display la temperatura...piu precisamente nel formato ad esempio -23.5 (i numeri al massimo possono essere quattro, quindi solo con un decimale per avere la possibilità di aggiungere il - nel caso la temperatura sia sotto lo zero)
Ho guardato due sketch di esempio per inviare i dati tramite I2C oppure tramite Seriale ma non sono riuscito a farlo funzionare correttamente. il sensore viene letto correttamente infatti tramite seriale sul pc compare la temperatura corretto ad esempio 23.50 .Solo che il passaggio successivo e cioé formattare il float per poi inviarlo al display non so come fare. Qualcusa sa come si può fare? Vi posto i codici. Grazie
invio dati tramite I2C
/*
11-2-2012
Spark Fun Electronics
Nathan Seidle
This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
Serial7Segment is an open source seven segment display.
This is example code that shows how to send data over I2C to the display.
Note: This code expects the display to be listening at the default I2C address. If your display is not at 0x71, you can
do a software or hardware reset. See the Wiki for more info:
http://github.com/sparkfun/Serial7SegmentDisplay/wiki/Special-Commands
To get this code to work, attached an Serial7Segment to an Arduino Uno using the following pins:
A5 to SCL
A4 to SDA
VIN to PWR
GND to GND
*/
#include <Wire.h>
#define DISPLAY_ADDRESS1 0x71 //This is the default address of the OpenSegment with both solder jumpers open
int cycles = 0;
void setup()
{
Wire.begin(); //Join the bus as master
Serial.begin(9600); //Start serial communication at 9600 for debug statements
Serial.println("OpenSegment Example Code");
//Send the reset command to the display - this forces the cursor to return to the beginning of the display
Wire.beginTransmission(DISPLAY_ADDRESS1);
Wire.write('v');
Wire.endTransmission();
}
void loop()
{
cycles++; //Counting cycles! Yay!
Serial.print("Cycle: ");
Serial.println(cycles);
i2cSendValue(cycles); //Send the four characters to the display
delay(1); //If we remove the slow debug statements, we need a very small delay to prevent flickering
}
//Given a number, i2cSendValue chops up an integer into four values and sends them out over I2C
void i2cSendValue(int tempCycles)
{
Wire.beginTransmission(DISPLAY_ADDRESS1); // transmit to device #1
Wire.write(tempCycles / 1000); //Send the left most digit
tempCycles %= 1000; //Now remove the left most digit from the number we want to display
Wire.write(tempCycles / 100);
tempCycles %= 100;
Wire.write(tempCycles / 10);
tempCycles %= 10;
Wire.write(tempCycles); //Send the right most digit
Wire.endTransmission(); //Stop I2C transmission
}
invio dati tramite Seriale
/*
9-23-2012
Spark Fun Electronics
Nathan Seidle
This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
Serial7Segment is an open source seven segment display.
This is example code that shows how to display basic numbers on the display.
Note: This code expects the display to be listening at 9600bps. If your display is not at 9600bps, you can
do a software or hardware reset. See the Wiki for more info:
http://github.com/sparkfun/Serial7SegmentDisplay/wiki/Special-Commands#wiki-baud
To get this code to work, attached an Serial7Segment to an Arduino Uno using the following pins:
Pin 8 on Uno (software serial TX) to RX on Serial7Segment
VIN to PWR
GND to GND
*/
#include <SoftwareSerial.h>
SoftwareSerial Serial7Segment(7, 8); //RX pin, TX pin
int cycles = 0;
void setup() {
Serial.begin(9600);
Serial.println("OpenSegment Example Code");
Serial7Segment.begin(9600); //Talk to the Serial7Segment at 9600 bps
Serial7Segment.write('v'); //Reset the display - this forces the cursor to return to the beginning of the display
}
void loop()
{
cycles++; //Counting cycles! Yay!
Serial.print("Cycle: ");
Serial.println(cycles);
char tempString[10]; //Used for sprintf
sprintf(tempString, "%4d", cycles); //Convert deciSecond into a string that is right adjusted
//sprintf(tempString, "%d", cycles); //Convert deciSecond into a string that is left adjusted (requires digit 1 command)
//sprintf(tempString, "%04d", cycles); //Convert deciSecond into a string with leading zeros
//sprintf(tempString, "%4X", cycles); //Count in HEX, right adjusted
//int negativeCycles = cycles * -1;
//sprintf(tempString, "%4d", negativeCycles); //Shows a negative sign infront of right adjusted number
//Note: This method works well as long as your number is less than or equal to 4 digits.
//14422 will cause the display to wrap (5 digits)
//-5766 will cause the display to wrap (5 digits)
//To fix this, send a 'v' character or look at how to control the digit placement
//https://github.com/sparkfun/Serial7SegmentDisplay/wiki/Basic-Usage#wiki-cursor
Serial7Segment.print(tempString); //Send serial string out the soft serial port to the S7S
delay(10);
}