Author Topic: My DigiSpark Car Interface Projects...  (Read 5813 times)

nperkins

  • Newbie
  • *
  • Posts: 3
My DigiSpark Car Interface Projects...
« on: March 03, 2014, 11:49:21 am »
Hi guys, I'm new to arduino and DigiSpark, but so far am having a blast.  I am always looking for DIY ideas for car things, and DigiSpark looks like its going to make that easy for me... I just picked up my DigiSpark, along with an RGB LED shield, a WiFi shield, and a CharliePlexed LED array...

So far, I have written two sketches..  If I'm doing things wrong, feel free to correct me. I'm always trying to learn.

#1.  Gear / Warning Indicator using CharliePlex LED array. 

For this, I took the Charlieplexing code that dmcinnes wrote for scrolling messages, and have removed the scrolling and offset portions of his code.  I also removed all character conversions not needed for an automotive transmission. (Hope you don't mind I butchered your code dmcinnes).   
Next, I will monitor the CAN output from my car's ECU (In this case a MegaSquirt), and use that to pickup vehicle speed & RPM, and then I will use a gear ratio calculator to determine when to show what gears.  Eventually I will expand it to work on regular OBD CAN output so you can use it on any car...

The only issue that I'm having now that I can't figure out is that I have a flicker on the CharliePlexed LED array. I don't THINK its code related though... Could it be I need to change the resistors to a different value than what is normally included?

#2.  RGB LED as shift light indicator.

For this, I used the RGB LED shield, and simply coded it so that when RPM's are in a certain range the colors shift from green, to yellow (Using PWM to get bright yellow), then red, then flashing red for an idiot light (over-rev).  Now I just need to figure out how to get the tach signal input into the Digispark (Could use help with this if somebody easily knows how).

Project #3 will be to make a "universal" gauge with a NeoPixel ring, and an LCD display (Possibly Nokia 5110) that can be customized using the CAN protocol for which gauge you want to display...  That's down the road though... 

As soon as I figure out how to attach my sketches here, i'll do it lol

nperkins

  • Newbie
  • *
  • Posts: 3
Re: My DigiSpark Car Interface Projects...
« Reply #1 on: March 03, 2014, 11:51:28 am »
Not sure if this is the right way to put my code on here, but here is the CharliePlexing code I'm using.  If there are things I can do to simplify, PLEASE let me know...  I want to spend some time getting rid of the string array stuff and going to straight string since i'm now always using a single string character, but everytime I try it doesn't get happy because of how it passes the pointers.

// where does our characterMap start in the ASCII code
#define MAP_START      32
#define DISPLAY_WIDTH  4
#define DISPLAY_HEIGHT 5
#define DISPLAY_STRING "6"


// maps characters to their 4x5 grid
//CharacterMap is a long value that can be up to 60 characters long
unsigned long characterMap[59];
char myString[] = DISPLAY_STRING;

// set up the character from the render map
void Chr(char theChar, unsigned long value)
{
  //Converts Character 2 to its long value
  characterMap[theChar - MAP_START] = value;
}

//Converts Character 2 to the myString array

void renderString(char *theString)
{
  renderCharacter(theString[0]);
}

// render a character on the given offset
void renderCharacter(char theChar)
{
  unsigned long graphic = characterMap[theChar - MAP_START];

  for (byte y = 0; y < DISPLAY_HEIGHT; y++)
  {
    for (byte x = 0; x < DISPLAY_WIDTH; x++)
    {
      if (graphic & 1)
      {
        lightPixel(3 - x, y);
      }
      graphic = graphic >> 1;
    }
  }
}

// light a pixel at the given coordinates
void lightPixel(byte x, byte y)
{
  //if x is less than or equal to 0 and x is greater than 4
  if (x >= 0 && x < DISPLAY_WIDTH)
  //if y is less than x then make x equal x + 1
  {
    if (y <= x)
    {
      x++;
    }
    LEDon(y, x);
  }
}

// turn on the pins to light a LED
void LEDon(byte vin, byte gnd)
{
  pinMode(0, INPUT);
  pinMode(1, INPUT);
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(vin, OUTPUT);   
  pinMode(gnd, OUTPUT);
  digitalWrite(vin, HIGH);
  digitalWrite(gnd, LOW);
}

// runs at start
void setup()
{
  // set up render map
  // Rows:   1---2---3---4---5---
  Chr('D', 0b11101001100110011110);
  Chr('N', 0b10011101101110011001);
  Chr('O', 0b01101001100110010110);
  Chr('P', 0b11101001111010001000);
  Chr('R', 0b11101001111010101001);
  Chr('X', 0b10011001011010011001);
  Chr(' ', 0b00000000000000000000);
  Chr('!', 0b01000100010000000100);
  Chr('1', 0b01100110011001100110);
  Chr('2', 0b11110001111110001111);
  Chr('3', 0b11110001111100011111);
  Chr('4', 0b10011001111100010001);
  Chr('5', 0b11111000111100011111);
  Chr('6', 0b10001000111110011111);
}

// loops continuously
void loop()
{
  renderString(myString);
}

nperkins

  • Newbie
  • *
  • Posts: 3
Re: My DigiSpark Car Interface Projects...
« Reply #2 on: March 03, 2014, 11:52:24 am »
Here is my code for the RGB LED shift light... at least where I'm at now with it.  I wrote it so that the RPM signal will be a variable thats easy to pass. 


void setup() {   

// initialize the digitals pin as an output.
pinMode(0, OUTPUT); //sets up pin 0 for pwm
pinMode(1, OUTPUT); //sets up pin 1 for pwm
pinMode(2, OUTPUT); //sets up pin 4 for pwm
}

void loop()
{
  int rpm = 0;
  //Turns on Green LED until 5500 rpm
  do
  {
    analogWrite(1,255);
    delay(2000);
    rpm++;
  }
  while (rpm > 5500);
  //Turns LED to Yellow until 7000 rpm
  do
  {
    analogWrite(0,240);
    analogWrite(1,60);
    rpm++;
    delay(2000);
  }
  while (rpm < 5500 & rpm > 7000);
 
  //Turns LED to Red until 7600 rpm
  do
  {
    analogWrite(0,255);
    analogWrite(1,0);
    rpm++;
    delay(2000);
  }
  while (rpm < 7000 & rpm > 7600);
  //Flashes Red LED over 7600 RPMs 
  do
  {
    analogWrite(0,255);
    delay(50);
    analogWrite(0,0);
    rpm++;
    delay(100);
  }
  while (rpm < 7600);
   
}

skyforce

  • Newbie
  • *
  • Posts: 3
Re: My DigiSpark Car Interface Projects...
« Reply #3 on: March 05, 2014, 09:42:13 pm »
Hi~

I'm a newbie with Digispark, I also working on car use HUD(Head Up Display) project at time for off work,
I named this project “Gearuino” means Gear + uino, and Gear means the main purpose of project is displaying the GEAR of transmission.

Maybe we can discuss about our project.

Here is my blog page about my project, but it is writing in Chinese, you can see the picture to guess what I'm doing.
http://sky4s.blogspot.tw/2014/01/gearuino.html