Show Posts
|
|
Pages: 1 2 [3] 4
|
|
32
|
Using Arduino / LEDs and Multiplexing / TLC5940 Changine to Bit Banging and Move Blank Pin????
|
on: November 21, 2012, 05:27:34 am
|
|
HI All,
I am currently developing a product that will use both the MCP CAN chips and also the TLC5940 LED Driver chip,
Both items run off Serial, and so i have to move the LED drive to Bit Banging mode, ( not a problem in itself ) but i also need to move the Blanking function pin of the TLC5940 from D10 on the Uno to another pin, as the CAN shield already uses this pin via the SPI interface,
Lookign throught the libraries that set up the TLC5940, i have had no luck changing this pin to D5, (also PWM capable)
I have tried changing the pinout library from PORTB2 to PORTD5 , D10 to D5 on the Uno, but no luck, it still uses D10,
Has anyone had any luck doing this , or running 2 serial chips from one serial out o the Uno?
Thanks
RIch
|
|
|
|
|
33
|
Using Arduino / LEDs and Multiplexing / Re: 8 x RGB LED Array
|
on: November 19, 2012, 04:37:47 am
|
|
Thanks, im just waitinf for the correct command from the cuy that wrote the library to try it out, but looks great,
Any idea why when the CAN message is removed, or i disconnect the board from the CAN bus, it seems to display the last recieved sequence on the lights,
In principal, it should be able to show more than one colour at a time as the CAN speed is high enough, and writing some simple code of digital write high's and low's allows me to do it,
I think i may have something in there that is taking to long, or it isnt clearing the messge buffer fast enough,
What do you think?
Cheers
Rich
|
|
|
|
|
34
|
Using Arduino / LEDs and Multiplexing / Re: 8 x RGB LED Array
|
on: November 16, 2012, 03:45:32 am
|
|
1, the CAN.ReadMsgBuf command in the code above will read the CAN messages that are being recieved into the message buffer.
Currently, i am using the contents of the CAN message frame eg, buf[1] being the first part, for the sequence of the LED's,
So weather the Message being sent had a base ID of 0x500 or ox600 , or any other base ID, the LED's would still do whatever the frame of data held.
i want to be able to "take notice" of only a single given CAN id to get my data from,
2, i tried doing this at the beginning of each loop, it seems to just cause the LED's to flash very quickly and at hardly any brightness, maybe i need to place it elsewehere in the loop?
3, thanks, i should have noticed that
Thanks
Rich
|
|
|
|
|
35
|
Using Arduino / LEDs and Multiplexing / Re: 8 x RGB LED Array
|
on: November 15, 2012, 11:29:56 am
|
Seems to be working great, Thanks for all of the help Crossroads, 3 questions 1, How can i set the CAN code up to look at only a single base CAN id, at the moment, regardless of CAN id, it simple recieves any message and uses the data in the melevant bits to run the lights, 2, How can i clear the message buffers at the beginning of each time through the loop? at the moment, once the CAN message is removed from the bus, the led's remain in the last message state, 3, Any way of getting the code to run faster, as i believe i can display multiple colours at a time in software as the CAN u[pdate rate is fast enough for visual deception,
#include "mcp_can.h" #include <SPI.h> #include <stdio.h> #define INT8U unsigned char
INT8U Flag_Recv = 0; INT8U len = 0; INT8U buf[8]; char str[20];
////////////////////////////////////////// CAN Setup Above
int x = 0; int pinsArray[] = {4,7,8,9,14,15,16,17}; // could be whatever group you select int maskBit = 1; int i = 0; ///////////////////////////////////////////////////// LED Setup Above
void setup()
{ for(i=0; i<8; i++) pinMode(pinsArray[i],OUTPUT); pinMode(3,OUTPUT); // Red PWM pinMode(5,OUTPUT); // Green PWM pinMode(6,OUTPUT); // Blue PWM
//////////////////////////////////////////////////////////////// LED Outputs Above
CAN.begin(CAN_500KBPS); // init can bus : baudrate = 500k attachInterrupt(0, MCP2515_ISR, FALLING); // start interrupt Serial.begin(115200);
////////////////////////////////////////////////////////CAN Begin Above }
void MCP2515_ISR() { Flag_Recv = 1; } /////////////////////////////////////////////CAN Calling code
void loop () {
if(Flag_Recv) // check if get data { Flag_Recv = 0; // clear flag CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf Serial.println("CAN_BUS GET DATA!"); Serial.print("data len = ");Serial.println(len); for(int i = 0; i<len; i++) // print the data { Serial.print(buf[i]);Serial.print("\t"); } Serial.println(); } ////////////////////////////////////////////////////////////////////////////////Recieve CAN Message analogWrite(3,buf[1]); analogWrite(5,buf[2]); analogWrite(6,buf[3]); ////////////////////////////////////////////////////////Set RGB Colour With CAN Message
maskBit = 1; // start with B00000001
for (x=0; x<8; x=x+1){ if ((buf[0] & maskBit) >0){ // makes all bits but 1 low: 0000000C, next pass 000000C0, etc
digitalWrite (pinsArray[x], HIGH); }
else { digitalWrite (pinsArray[x], LOW); }
maskBit = maskBit << 1; // next bit - B00000010, B00000100, B00001000, etc up to B10000000 }
////////////////////////////////////////////////////////////////////////////////////////////////Write LED Pattern }// next x
|
|
|
|
|
38
|
Using Arduino / LEDs and Multiplexing / Re: 8 x RGB LED Array
|
on: November 15, 2012, 05:31:41 am
|
|
Sorted, a few tweaks and i am there, i had to replace the == operator at the top of the loop with a single = operator as it was running a comparison and getting stuck,
will follow up with some updates when i have meged the PWM colour code and CAN recieve and transmit code into the main code.
Thanks again
Rich
|
|
|
|
|
39
|
Using Arduino / LEDs and Multiplexing / Re: 8 x RGB LED Array
|
on: November 15, 2012, 04:41:18 am
|
OK, so i have managed to get the code to start running, and modifying the decimal number where the CANbyte value was will give me the desired LED patter, The isue being, that is only flashes up for a second and it doesnt seem to be running through the loops correctly, I have had a look over it and i cant spot anything obvious, I had to add a "<" to the Maskbit line at the bottom as i assume it was supposed to be a Bitshift command? is thios correct? Appreciating all the help folks RIch int x = 0; int pinsArray[] = {2,3,4,5,6,7,8,9}; // could be whatever group you select int maskBit = 1; int i = 0;
void setup()
{ for(i=0; i<8; i++) pinMode(pinsArray[i],OUTPUT); pinMode(10,OUTPUT);
maskBit == 1;
}
void loop () { digitalWrite(10,HIGH); // start with B00000001
for (x=0; x<8; x=x+1){ if ((255 & maskBit) >0){ // makes all bits but 1 low: 0000000C, next pass 000000C0, etc
digitalWrite (pinsArray[x], HIGH); }
else { digitalWrite (pinsArray[x], LOW); }
}
maskBit = maskBit<<1; // next bit - B00000010, B00000100, B00001000, etc up to B10000000
}// next x
|
|
|
|
|
40
|
Using Arduino / LEDs and Multiplexing / Re: 8 x RGB LED Array
|
on: November 15, 2012, 03:22:22 am
|
I tried running your code, i had to move a few colons and add a few braces to get it to compile, but i dont seem to get any output, Just for now i have replaced the CANbyte with a decimal number , i assume this should not be an issue, code posted below int x = 0; int pinsArray[] = {2,3,4,5,6,7,8,9}; // could be whatever group you select int maskBit = 1; void setup() { pinMode(pinsArray[8],OUTPUT); } void loop () { maskBit = 1; // start with B00000001 for (x=0; x<8; x=x+1){ if ((126 & maskBit) >0){ // makes all bits but 1 low: 0000000C, next pass 000000C0, etc digitalWrite (pinsArray } else { digitalWrite (pinsArray } } maskBit = maskBit<1; // next bit - B00000010, B00000100, B00001000, etc up to B10000000 } // next x
|
|
|
|
|
41
|
Using Arduino / LEDs and Multiplexing / Re: 8 x RGB LED Array
|
on: November 14, 2012, 10:09:24 am
|
|
Im stuggling a little bit with the maskbit , as i am unsure of the purpose this is serving,
The number i want to send to the array is in decimal, and i want the array to conver it to a binary representation,
is the byte command used for this?
thanks
Rich
|
|
|
|
|
42
|
Using Arduino / LEDs and Multiplexing / Re: 8 x RGB LED Array
|
on: November 13, 2012, 01:55:58 pm
|
|
OK, thanks crossroads for all the help, when i am at work tomorrow, i will try setting that code up, i am fairly new to programming, and i have seen a few examples of sending a binary number to 8 led's, but they all seem to step through a sequence as a counter rather than pulling the value required from a data stream,
I really appreciate all of your help and will give it a go tomorrow and let you all know the results,
I plan on developing this into a product, as the hardware side of things is simple for me,
I will post all my results , schematics, and CAn templates here once i have something better to report than simple questions,
Thanks again
Rich
|
|
|
|
|
43
|
Using Arduino / LEDs and Multiplexing / Re: 8 x RGB LED Array
|
on: November 13, 2012, 03:16:44 am
|
|
Thats fine, but all of the pattern data is on Byte 1 only,
What i am struggling with, is the the command to pass the 0 to 255 value from the CAN message to the 8 digital outputs to turn the corresponding LED's on
I was assuming there is some clever command that passes an 8 bit integer to 8 defined output pins,
I am probably hoping a bit too much there i guess?
RIch
|
|
|
|
|
44
|
Using Arduino / LEDs and Multiplexing / Re: 8 x RGB LED Array
|
on: November 12, 2012, 02:44:38 pm
|
So i have the hardware built, I have the code written to take the CAN id and write it out to the PWM pins for Red, Green and Blue Brightness, Now i need to figure how to get the 0-255 value i get on the first bit of the can message, to control the 8 LED pins in binary order, a bit like a counter, I had been using byte - as the command for the PWM pins, i,e, analogWrite(3byte[3]0;
So it would be byte[1] for the pattern, How do i do a simple binary output to the 8 led pins corresponding to the value in the CAN message? Hope you can help guys
|
|
|
|
|
45
|
Using Arduino / LEDs and Multiplexing / Re: 8 x RGB LED Array
|
on: November 11, 2012, 04:55:30 pm
|
|
Why would I to need to multiplex the cathodes? As if I wanted 3 greens on for example, I could simply activate the corresponding pins,
Yes that is exactly how the "pattern bit" should work, So I have to find a way of relieving the pattern bit and turning that into the corresponding output.
Thanks so far
|
|
|
|
|