Show Posts
Pages: 1 [2] 3 4 ... 9
16  Using Arduino / Project Guidance / Re: Car led system or CARduino on: February 10, 2011, 04:32:45 pm
I have been doing something similar over the last year for my motorcycle.
http://arduino.cc/forum/index.php/topic,8381.0.html

I started it last spring.  But then the weather got warm and I would rather spend my time on the motorcycle smiley  I was also delayed because customs held my bliptronic leds for a couple of months.

I have gone through 4 different designs because I keep adding features.  I'll give you a quick summary of what I have done and why.
My original plan was to make some accent LEDs that I can control and make custom effects.  I wanted to control them remotely and I wanted the ability to add effects later on easily.  I found a 4 button remote.  I will have a microsd card holding animation information.  Some animations have to be programmed - anything that has random numbers.  The microsd card will will contain frame based effects. 

I started with a tlc5947 led driver chip as that is the first thing I came across in my research.  The first video in that post is me making sure I can control the chip.  Those LEDs are once I had around and they are a pain to work with.  I found a led strip on ebay that takes 12v (perfect for a car or bike) that could be cut and used like individual LEDs with the tlc chip.  I got that all working fine.

Then I saw the Bliptronic pixel LEDs.  I really liked that idea over the tlc5947 because it would be a lot less wiring.  In a car, you can hide wires in door panels and such.  On a motorcycle, not so much.  So I picked up some of those.  They work great but I ran into a problem.  Since you have to manually control the PWM cycle that takes up processing power.  Some of my more complex animations affected that causing the LEDs to flicker. 

Luckily, the next week Sparkfun came out with their addressable LED strip.  The chip they use has it's own PWM cycle.  That is a super easy LED strip to work with.

Right now I am in the process of converting the code to a Netduino Plus.  The Netduino Plus has built in ethernet and microsd.  This gives me more I/O pins for future expansion.  Plus the fact that I can do line by line debugging makes it easy to code. I am going to use a small wifi router connected to the ethernet port and control it with my ipod touch instead of the remote.

I am still going to finish the project with the Arduino as my sister wants the basic setup on her bike.  One idea for future expansion is to use xbee or some other wireless communication between my bike and my sister's bike to have in sync animations when our bikes are next ot each other.

When I ordered the Bliptronic LEDs I also grabbed the audio analyzer shield.  I will add some modes where the LEDs are controlled by music.

Finally, FYI, the US government definition of amber warning lights is actually orange.  100% red, 50% green.  I was going to use my LEDs as running lights (anything to make a motorcycle more visible) but running lights are only legal on trucks and emergency vehicles.
17  Using Arduino / Project Guidance / Using a cellular module on: February 10, 2011, 03:21:04 pm
I am working on a HUD speedo for my motorcycle.  It should be easy enough, just and arduino, gps shield, and 4 digit 7 segment led.  I got that part working (other than a defective gps module).  This got me thinking, I will always have a gps on my bike then maybe I can track my bike.  After some research it seems the best way to do this is to get a cellular shield and send SMS somewhere.

i have a couple questions about this.  First, does anyone have experience with this in the US?  If so what cell plan do you have? 

I only need a text plan and I found one from a company called Qwert that offers 400 messages a month for $11 or unlimited for $20.  After reading their terms agreement I could do the 400 per month if I am careful.  I wonder if this is enough.  I would have to keep track of how many are sent and find a rate that keeps me within that limit.  Maybe base in on once every 5 minutes or every 2 miles or something.  I would have a switch so I can manually keep the device from sending messages if I need to.  Then to create balance have a button to force a message to be sent.  If the message count is high, say 370 or greater, I can indicate that by turning on one of the decimal points.  If at limit I could turn on all decimal points.

The other issue is to get the SMS messages to google maps.  I think I have a solution for this.  Send the SMS to a twitter account.  The SMS will be in the format of RideID, TimeStamp, Long, Lat.  Then I could make a php script on my website to use the twitter api that gets the last 20 status messages and put them on a google map.  This seems kind of like a hack though.  Anyone know a more elegant way?
18  Development / Suggestions for the Arduino Project / SD card suggestion on: January 26, 2011, 02:07:35 pm
Some type of mechanism for traversing through the files of a directory.

In sdfatlib you did something like this:
dir_t dir;
char name[13];
while(folder.readDir(&dir) != sizeof(dir))
{
SdFile::dirName(dir, name);
//Then do whatever with the file or file name
}
19  Community / Website and Forum / Add a data storage forum? on: January 26, 2011, 11:34:28 am
Add a data storage forum to talk about SD card, eeproms, etc...  The SD card thread in the old forums was one of the largest.
20  Forum 2005-2010 (read only) / Troubleshooting / Re: Possible bug with % operator: can you repeat it? on: February 12, 2010, 01:13:05 pm
ind is an int.  MAX_NUM is 10.  When ind is 0 it will end up at -1 without that if.

Edit: ok, so signed behaves differently.  Will switch to unsigned.
21  Forum 2005-2010 (read only) / Troubleshooting / Possible bug with % operator: can you repeat it? on: February 12, 2010, 12:43:39 pm
I have to try this with 0018, I just realized I am on 0016.  This is why I am not posting it in the bugs forum.  I am not going to have access to my project for a couple of days.  Does this problem occur with someone else?

I have to do this
Code:
ind = ((ind-1) % MAX_NUM);
if(ind < 0) { ind = MAX_NUM-1; }

It seems like mod isn't working when I subtract values.
22  Forum 2005-2010 (read only) / Syntax & Programs / Re: Counting Elements in an array passed to a function on: October 04, 2010, 07:04:41 pm
Quote
I can't figure out how to get the size of the array the pointer points to inside the function.
Not possible.  You send in a pointer to an array, which just points to where in memory the array is at.  No way to get size off a memory pointer.  That is why functions that allow you to send in an array also ask for size of array.
23  Forum 2005-2010 (read only) / Syntax & Programs / Re: determining if enough to memory to dynamic alloc on: February 11, 2010, 08:20:07 pm
Is there any other way than reading a file into memory?  Most fat libraries I see only do writing for gps logging.  I haven't seen much for reading sd cards.  

The file format will be:
first byte is the number of commands available
second byte is type of command
Then for however many commands there are a byte containing a delay in millisecond to run next command.
The rest of the file will be the commands - individual command size will depend on command type.
24  Forum 2005-2010 (read only) / Syntax & Programs / determining if enough to memory to dynamic alloc on: February 11, 2010, 04:37:28 pm
I am trying to figure out how to determine how much memory there is, either eeprom or progmem, and if there is enough memory to allocate an object.

What I plan on doing is have a microSD card with files on it.  The files will have commands.  This way I can add more commands just by dropping files onto the card.  Obviously then the number of commands in a file is dependent on the amount of memory available to load the file.  so I will need to determine if a file can be loaded.

any ideas?
25  Forum 2005-2010 (read only) / Syntax & Programs / Re: division on: October 07, 2009, 01:15:59 am
Do you have to do the 5.0f thing with the arduino code?
26  Forum 2005-2010 (read only) / Syntax & Programs / Re: Boolean Vs. Bitwise on: October 07, 2009, 02:51:55 am
Why would you use bitwise operators?  It can save memory and it is fast.


Let's say you have 8 LEDs, each connected to a pin on the arduino.  This means one the first pass the first LED is on and the rest are off.  On the next pass the second LED is one and the rest are off.  On the third pass the third LED is on and the rest are off.  And so forth, repeating over and over.

To do this you will need to keep track of the state of each LED so you know if you need to turn it on or off.  Many new programmers would make an array of integers like int led_states[8];  Then set each array value to HIGH or LOW.  There's a lot of wasted space there since we just need to know 1 or 0.  We can store the information in a single uint8_t value where each bit is the state of the corresponding LED.


To make a chase animation you could do something like this (assuming the LEDs are pin 5-13):
Note: this is still some sloppy code, I know some are saying it can be written better.  I wrote it this way so it is obvious what is going on.
Code:
uint8_t led_state = 0;   //start state of 00000000 in binary

void loop()
{
      //shift value to the left one space
      //For example 00000001 becomes 00000010
      led_state <<= 1;

      //check if we shifted the 1 too far
      if(led_state == 0)
            led_state = 1;  //reset to 00000001
      
      //update the LEDs
      for(int i = 0; i < 8; i++)
      {
            //First shift 1 to the left to the LED we are checking
            //then AND that result with the the led_state to filter that bit
            //then shift back to the right so we have either 1 or 0 (HIGH or LOW)
            digitalWrite(5+i; ((led_state & (1 << 1)) >> i));
      }
}
27  Forum 2005-2010 (read only) / Syntax & Programs / Re: Boolean Vs. Bitwise on: October 07, 2009, 01:54:32 am
To add to what mem said:

&& and || are a logical operators for AND and OR
& and | are a bitwise operators for AND and OR

mem explained the logical operators.  They are used to compare logical operations - true and false states.  For example:
if(a> 3 && b <= 88)
{
   //The code here will execute if a is greater than 3 AND
   // b is less than or equal to 88
}


Bitwise operators work at the bit level.  Here's a quick tutorial on bitwise operators.  There are 6 of them.

Let's start with these variables
uint8_t a = 0x3B //00111011;
uint8_t b = 0x96 //10010110;

We will start with AND, OR, XOR, and NOT.  These operators compare each bit between two values.

AND (& in C):

AND compares each bit and returns 1 if the two bits are 1 (true) otherwise 0 (false).
So:
c = a & b;

c's value will be 0x12 or in binary 00010010.  That is where there is a 1 in each bit for both values.

OR (| in C)
OR will return a 1 if there is a 1 in either value at that bit.
So:
c = a | b;

c's value will be 0xBF or in binary 10111111

XOR (^ in C - pronounced exclusive OR):
XOR will return a 1 if there is a 1 at that bit for either value but not both.  For example, if bit position 5 for both values has a 1 then XOr returns a 0.  But if only one has a 1 and the other has a 0 XOR returns a 1.
So:
c = a^b;

c's value is 0xAD - binary 10101101

NOT(! in C)
This returns the compliment of a value.  This mean where there was a 0 there will now be a 1 and visa versa.
So:
c = ~a;

c's value will be 0xC4 - binary 11000100

Sometimes it is easier to visualize the values if they are above each other, like:

Code:
 00111011
& 10010110
----------
= 00010010

  00111011
| 10010110
----------
= 10111111

  00111011
^ 10010110
----------
= 10101101

 !00111011
----------
= 11000100


And then there are two shift operators - left shift and right shift.  These shift the bits by the corresponding value - in otherwords move the bits over.  << for left shift and >> for right shift.
So:
c = a << 2;  // left shift a by 2
d = b >> 4; // right shift b by 4

c's value is 0xEC - binary 11101100
d's value is 0x03 - binary 00001001


28  Forum 2005-2010 (read only) / Syntax & Programs / Re: Help with dynamically adding elements to an array on: September 10, 2009, 02:09:18 am
There's a couple things you can do.

You could setup a simple protocol, something like
<STX>3<CR>command1<CR>command2<CR>command3<EOT>

<STX> is ascii  0x02, <CR> is ascii 0x0d, and <EOT> is 0x04.

STX will indicate the beginning of the command list which will be separated by CR characters and end with the EOT character.  The first value will be how many commands to be received - make it a single byte.  This would allow you to allocate the appropriate amount of memory.  I would make the commands one byte - the left most bit will be 1 or 0 for high or low.  The rest of the bits to specify the pin.  ACtually, if you kept everything to one byte sizes you wouldn't need the <CR>.  You know the first byte after a STX is the number of bytes to read to get all of the commands.  The EOT wouldn't really be needed then either.  However, it would help you determine if the correct amount of commands were sent.

There are dynamic array classes for C++ out there, but I would think a simple protocol with memory management would be more efficient.

Edit: my bad - you wouldn't want the start and end bytes to be STX and EOT.  They could get confused with commands w=since STX = 0x02 and EOT is 0x04 - which could be confused with the commands to turn off pins 2 and 4.  So make the bytes something like 0x80 and 0x81.

My C is rusty so the syntax may not be 100% accurate, but you should get the idea.  

To encode a command it would be like
Code:
byte encodeCommand(byte state, byte pin)
{
      //example: byte command = encodeCommand(HIGH, 2);
      //will mean pin 2 high
      //wiring.h for the arduino defines HIGH as 0x1 and LOW as 0x0
      //So shift that value to set it as the left more bit or the return but
      //then and it with the pin.
      //Pin 2 on high should give you the byte 10000010
      return ((state << 7) & pin);
}

void decodeCommand(byte command, byte &state, byte %pin)
{
      state = (command >> 7);
      pin = (command & B01111111);
}

If you really want to save on memory you can replace the decodeCommand with a doCommand(byte command) that contains one line of code: digitalWrite((command & B01111111), (command >> 7);

After you read the byte that defines the number of commands to be send you can use realloc to reallocate the array to the approiate size.  You will also need to keep track of the array size. Once you create the array if you make a processCommands() function the parameters would be (byte *commands, byte size).

Word of warning.  Read up on how to use realloc, malloc, calloc, and free properly so you don't run into memory leaks.
29  Forum 2005-2010 (read only) / Syntax & Programs / Re: Arduino on a Mac on: August 21, 2009, 11:46:37 pm
thanks
30  Forum 2005-2010 (read only) / Syntax & Programs / Arduino on a Mac on: August 20, 2009, 01:15:58 pm
I want to use this library but I am not sure where to put it on a mac.
Pages: 1 [2] 3 4 ... 9