Show Posts
Pages: 1 2 [3] 4 5 ... 9
31  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


32  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.
33  Forum 2005-2010 (read only) / Syntax & Programs / Re: Arduino on a Mac on: August 21, 2009, 11:46:37 pm
thanks
34  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.
35  Forum 2005-2010 (read only) / Interfacing / Interfacing with a fonera on: September 11, 2009, 10:05:30 pm
I've seen youtube videos of an arduino sending data to a fonera router.  What I would like to know is how one would setup a webserver on the fonera (with dd-wrt I am sure) and have it send data to the arduino over it's serial port.  For example, let's say I ahve an LED on the arduino that I want to turn on and off with the webserver built into the fonera.  How would I have a webpage/script send data over the serial port?
36  Forum 2005-2010 (read only) / Development / Re: Programming through wifi on: September 16, 2009, 10:57:15 pm
That still requires a wireless access point.  The WiShield, as far as I can tell, can not give out dhcp addresses and automatically have the web browser go to a page.

I am not sure I could achieve what I want with ad hoc.
37  Forum 2005-2010 (read only) / Development / Re: Programming through wifi on: September 13, 2009, 10:41:25 pm
True.  I'm just looking at my options.

If the bluetooth arduino wasn't so expensive I would go that route.
38  Forum 2005-2010 (read only) / Development / Re: Programming through wifi on: September 12, 2009, 10:27:11 pm
I just read how the auto-reset works.  That might be a possibility.  I wonder if the command line stuff supports that.

Thanks for giving me a place to start.  I will be looking into this.

I am making an LED controller for my motorcycle.  I plan on hooking up the arduino to a fonera router running dd-wrt.  I am going to set it up so anyone can connect to the AP and control the colors of the LEDs through a web server on the fonera.  

Because of this if I make a new program with different LED fades and such it would be nice to upload the program without taking the arduino out.  I plan on putting the arduino in the fairing so taking the fairing apart each time would be annoying.
39  Forum 2005-2010 (read only) / Development / Programming through wifi on: September 12, 2009, 01:23:45 pm
I have a thought on this.  Does the arduino software have a command line interface?  If not I suppose I could look into adding it.

I am looking at connecting an arduin to a fon router though the serial port.  In theory I could install the arduino software on a fon with dd-wrt.  If the arduino software has a command line interface I could could make a web page to up load a program and then program the arduino.

Doesn't the serial interfaced used to upload a program to the arduino the same as a couple of the pin available?  If so how does the arduino know the difference between uploading code and program communications?
40  Forum 2005-2010 (read only) / Troubleshooting / Timer1 on: October 04, 2010, 11:44:36 am
The playground page for Timer1 says "Note that this breaks analogWrite() for digital pins 9 and 10 on Arduino."  Digital write and read would still work for those pins though, correct?
41  Forum 2005-2010 (read only) / Troubleshooting / Re: Error with Lilypad & Bluetooth Mate on: February 13, 2010, 10:53:04 pm
I get that also.  But if I wait abit and try again I get the following errors.
avrdude: stk500_getsync(): not in sync: resp=0x00
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51
42  Forum 2005-2010 (read only) / Development / Re: LED Project-- is it possible? on: September 02, 2009, 12:49:16 am
You don't need an arduino for that.  There are several VU meter ICs out there.  Most work with line out - which I am not sure what a car stereo would have.  Line out is not an amplified signal.  To do a spectrum analyzer you will have to look into different filters.  High pass, low pass, and band pass I believe.
43  Forum 2005-2010 (read only) / Interfacing / Re: Bliptronic LEDs with SPI on: October 03, 2010, 12:25:21 am
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1285962975
44  Forum 2005-2010 (read only) / Interfacing / Re: fast spi library - add SPI CS on: October 01, 2010, 04:58:41 pm
I assume that fast spi library works and solves the issues you mentioned.  I haven't been around my project yet to try the library.  But it seems like it must work as the example code is bliptronic's code converted to using the library.

I get what you are saying.  It is the same reason you suggested to me to blank the TLC5947 before sending data - to reset the PWM cycle.

So, assuming the library is keeping track of where the beginning of the PWM cycle is - hardware wise does my idea work?  Because the idea could be applied to other hardware, not just LEDs.

I wish there was a datasheet on that IC that was in english.
45  Forum 2005-2010 (read only) / Interfacing / fast spi library - add SPI CS on: October 01, 2010, 02:56:15 pm
This is a software and hardware interfacing question, but I am going to start with the hardware first.

I am using the bliptronic (lpd6803) leds in my project.

Looking at bliptronic's example code the timer simulates a single clock cycle, correct?  That means the LEDs are getting updated rather slowly.  Then I found the fast spi library for them.  However, I am already using an SPI device with cable select in my project.  So that means I would have to add a CS - also modify the library to use it, but that is the next step.

To add CS to the LEDs would it be as simple as to hook up a transistor to the the CS pin and between the MOSI arduino pin and data pin on the LEDs?  Or does it need to be a relay?


http://code.google.com/p/fastspi/
Pages: 1 2 [3] 4 5 ... 9