on the complexity of the 7segment circuitry for a project like a car digital dashboard.
About a month ago I discovered those neat 7segment displays based on the TM1638 chip
that are incredibly cheap and its layout is very close to the one I wanted. You can see them
here: http://www.dealextreme.com/p/8x-digital-tube-8x-key-8x-double-color-led-module-81873
To drive the display and connect it to x-sim through USO interface I used a also cheap Arduino module
compatible with Arduino Nano. See it here: http://dx.com/p/nano-v3-0-avr-atmega328-p-20au-module-board-usb-cable-for-arduino-118037
So the total cost of this project is only $19.98 !!
See it in action here:
And here a new video different camera:
And here with two TM1638 displays, were the second displays the PRM as numerical.
The wiring is very easy:
Prodigy's schematic (thanks Prodigy)
Here is the code for this first version. I hope next version will has some use for the buttons as well.
- Code: Select all
// X-sim3dashboard v1 (using TM1638 display and Arduino Nano v3)
// Made by TronicGr (Thanos) 4-26-2012 for X-sim3
// Shared as Public Domain
// Serial parser example: R~a01~~95~S~a02~G~a03~
// Where:
// ~a01~ is 16bit value for rpm
// ~95~ is data value parameter for RPM_MAX divided by 100 to fit into a byte so actual value is 9500
// ~a02~ is 16bit value for speed
// ~a03~ is 8bit value for gear / neutral / reverse
// You can set the USO pause safely to 10ms for nice fast refresh rates!
#include <TM1638.h> //can be downloaded from http://code.google.com/p/tm1638-library/
// define a module on data pin 5, clock pin 4 and strobe pin 3
TM1638 module(5, 4, 3);
void setup() {
//Create Serial Object
Serial.begin(115200);
// initialize the screen:
module.clearDisplay(); //clears the display from garbage if any
String name = "TronicGr"; //sets a custom logo start up banner
module.setDisplayToString(name); //prints the banner
delay(1500); //small delay 1.5 sec
module.clearDisplay(); //clears the display
}
void loop() {
int i;
char bufferArray[20]; // holds all serial data into a array
unsigned int rpm; //holds the rpm data (0-65535 size)
unsigned int rpmleds; //holds the 8 leds values
unsigned int rpmmax; //retrieves from x-sim USO this value as parameter divided by 100
unsigned int carspeed; //holds the speed data (0-65535 size)
byte gear; // holds gear value data
byte d1; // high byte temp variable
byte d2; // low byte temp variable
byte rpmdata = 0; // marker that new data are available
byte speeddata = 0; // marker that new data are available
byte geardata = 0; // marker that new data are available
if (Serial.available() >= 9) { //if 6 bytes available in the Serial buffer...
for (i=0; i<9; i++) { // for each byte
bufferArray[i] = Serial.read(); // put into array
}
}
if (bufferArray[0] == 'R' ){ // if new bytes have been recieved
d1 = bufferArray[1]; // store high byte of rpm
d2 = bufferArray[2]; // store low byte of rpm
rpm = ((d1<<8) + d2); // concatonate bytes (shift 8 bits)
rpmmax = bufferArray[3]; // retrieves the maxrpm value
rpmmax = (rpmmax * 100)+500; // multiplies the rpm data into thousants
rpmdata=1; // we got new data!
}
if (bufferArray[4] == 'S' ){
d1 = bufferArray[5]; // store high byte of speed
d2 = bufferArray[6]; // store low byte of speed
carspeed = ((d1<<8) + d2); // concatonate bytes (shift 8 bits)
speeddata=1; // we got new data!
}
if (bufferArray[7] == 'G' ){
gear = bufferArray[8]; // retrieves the single byte of gear (0-255 value)
geardata=1; // we got new data!
}
if (speeddata == 1) {
module.setDisplayToDecNumber(carspeed, 0, false); //displays numerical the speed
speeddata=0;
}
if (geardata == 1) {
char* neutral = "n"; // sets the character for neutral
char* reverse = "r"; // sets the character for reverse
gear = gear - 127; // offset the 0 value in 8-bit
if (gear >= 1 and gear <10 ){
module.setDisplayDigit(gear, 0, false); // displays numerical value of the current gear
}
if (gear == 0){
module.setDisplayToString(neutral, 0, 0); // displays the character for neutral
}
if (gear == 255){ // -1 that reprecents reverse rollover to 255 so...
module.setDisplayToString(reverse, 0, 0); // displays the character for reverse
}
geardata=0;
}
if (rpmdata == 1) {
rpmleds = map(rpm,0,rpmmax,0,9); // distributes the rpm level to the 8 leds + 1 for shift change
if (rpmleds==0){
module.setLEDs(0b00000000 | 0b00000000 << 8);
}
if (rpmleds==1){
module.setLEDs(0b00000000 | 0b00000001<< 8 );
}
if (rpmleds==2){
module.setLEDs(0b00000000 | 0b00000011<< 8 );
}
if (rpmleds==3){
module.setLEDs(0b00000000 | 0b00000111<< 8 );
}
if (rpmleds==4){
module.setLEDs(0b00000000 | 0b00001111<< 8);
}
if (rpmleds==5){
module.setLEDs(0b00000000 | 0b00011111 << 8);
}
if (rpmleds==6){
module.setLEDs(0b00100000 | 0b00011111<< 8 );
}
if (rpmleds==7){
module.setLEDs(0b01100000 | 0b00011111<<8 );
}
if (rpmleds==8){
//module.setLEDs(0b11100000 | 0b000011111<<8 );}
module.setLEDs(0b11111111 | 0b111111111<<8 );
}
rpmdata=0;
}
}
The serial parser can be for example: R~a01~~95~S~a02~G~a03~
Where:
~a01~ is 16bit value for rpm
~95~ is data value parameter for RPM_MAX divided by 100 to fit into a byte so actual value is 9500
~a02~ is 16bit value for speed
~a03~ is 8bit value for gear / neutral / reverse
Here is the saved profile that contains the math and the axis definitions for the rpm/speed/gear along with some photos of the settings.
The above video of a modification by vicpopo--> http://www.x-sim.de/forum/viewtopic.php?f=40&t=155&start=30#p5495
Newer version with bigger Gear Digit!
Thanos