FTDI TTL-232 Cable LED Blinking

I have a small project :slight_smile: similar to this viewtopic.php?t=38429

My plan is to write a program which will load a text file to an array in memory and activate an LED based on a certain element’s value in the array, 0 or 1. I will evaluate 120 elements of the array per second.

How do I get the 0’s and 1’s to be significant? That is the fun part! Taking baby steps, first I will use generated values from functions like cosine or even just simply constant functions. I will use this method while working out the hardware side of things. Second I am going to use values generated by a beat tracking program from the MARSYAS project at http://marsyas.info Ultimately my hopes are to create a program that will allow me to ‘compose’ the light based on key presses corresponding to functions that will write into an array the 0’s and 1’s that are later played back with the music.

The conceptual idea I thought up was this: Have FTDI usb cable switch a relay which is on the circuit between a 12v battery and a strip of LEDs.

Im trying to keep as much control in the hands of my program as possible.

So far I have bought this stuff :slight_smile:

FTDI TTL-232R-5V … Datasheet : http://www.ftdichip.com/Support/Documen … CABLES.pdf

Breadboard and breadboard wires

Mechanical Relay: DPDT from Radioshack… Datasheet : http://www.radioshack.com/graphics/uc/r … _DS_EN.pdf it says its a 12v coil, does that mean i cant switch it with 5v?

I will be purchasing LED strips in the future. right now I am testing with a single 5v red LED.

The reason I am posting this thread is because I do not know much about electronics at all.

These are my questions.

Why does this code only blink the LED connected to GND and CTS slowly?

#include <iostream>
#include <stdio.h>
#include <ftdi.h>
using namespace std;
#define LED 0x08 // cts line on cable
int main()
{
    unsigned char c = 0;  
    struct ftdi_context ftdic;
    ftdi_init(&ftdic);
    cout << ftdi_usb_open(&ftdic, 0x0403, 0x6001) << endl;  

    ftdi_set_bitmode(&ftdic, LED, BITMODE_BITBANG);
//    ftdi_set_baudrate(&ftdic, 3000000);
//    ftdi_write_data_set_chunksize(&ftdic, 1);
    c ^= LED1; // c = 8
//    c = 255;
    
    for( ; ; ) ftdi_write_data(&ftdic, &c, 1);
}

Before running this code the led does not blink.

During executiin the LED binks regularly. 1 blink/second approximately

After stoping execution the LED continues to blink.

Uncommenting the commented lines produces the exact behavior.

While this code is running if I plug my relay switch into GND and CTS, where the LED would have blinked, nothing happens.

If i plug the relay switch into VCC and GND then, where the LED would blink, the switch turns on and stays on… ( i can here the click of the switch ).

I took the basic idea of this code from this website http://hackaday.com/2009/09/22/introduc … bang-mode/ I’m going to test exactly what happens to my LED when the example code is used from this site tonight just to double check. I always was confused what the line ```
c ^= LED


I just read the FTDI Application Notes on BitBang Mode for their 232r devices here [http://www.ftdichip.com/Support/Documen ... Ft245R.pdf](http://www.ftdichip.com/Support/Documents/AppNotes/AN_232R-01_Bit_Bang_Mode_Available_For_FT232R_and_Ft245R.pdf) and am going to rethink my blinking code tonight.

Will a mechanical DPDT relay switch fast enough for my application? (greater than or equal to 60 times/second)

If not, should I use a solid state relay?

Does anybody have any suggestions? Ive considered using my raspberry pi I have laying around.

Any help is greatly appreciated, thanks.

I haven’t yet grok’ed your entire post but I will say this …

Will a mechanical DPDT relay switch fast enough for my application? (greater than or equal to 60 times/second)

The answer is no. And if you could find one fast enough, it would wear out pretty quickly. This is a job best done by power FETs.

I am very confused by your choice of some FTDI cable to do your task. I think there are much better ways but I’ve yet to understand the entire nature of your task. Could you rephrase it ? Tell “us” the functions you want to see implemented w/o telling us how you’d do it. As you said …

The reason I am posting this thread is because I do not know much about electronics at all.

For example ... *I want a string of LEDs to illuminate in sync w/the beat of music. And ...*

You posted some code. Was your intention to run your system off a PC (or Mac) directly or to have an Arduino (or some other microcontroller, aka MCU) do the task ? The thread you linked to was of the latter variety. I believe Marsyas is a program that runs on a PC (or Mac). Where does the initial raw data (?a text file?) come from ?

Thanks for the reply, I hope this clears things up.

I am trying to light the LEDs according to the perceived beat of the music.

So I’m trying to first nail down just blinking the LED when I tell it to in code, and to do it fast. Then I will implement more interesting things with programming code.

I’ve considered 3 different ways to blink the LEDs.

  1. manually blinking the LED as the first code example tried to do, (constantly on);

  2. using precomputed output from marsyas.

  3. using precomputed output ive created by pressing keys (playing the light as a ‘piano’, maybe there is already software that does this idk)

Method 2: Marsyas can output the time during a song that it has detected a beat. I can use these timings to write (programmatically) an array of 0s and 1s.

Method 3: Marsyas is nice but not perfect, so I want to create or find a program that will allow me to ‘compose’ the array of 0s and 1s with my keyboard.

Both method 2 and 3 will end with an array of 0s and 1s which can be saved to a file and read back later.

Later I can use the file to turn the LEDs on and off which will the make the LEDs pulse to the beat.

The reason I chose the FTDI cable is simply because it looked simple to me and my noobness. I probably could use a regular FT232R module that plugs into the breadboard nicer and has more pins.

I will be able to run the code that blinks the LEDs off any device that has a recent linux kernel, a usb port and which can compile/run the code.

I’ll test on both a pc running linux and a linux chroot on my android tablet. The above code works on both my pc and my tablet.

The LEDs will be placed in the interior my car. I plan on putting the final program on my tablet so I can just leave the hardware in the car and simply plug in a usb to the electronics and play the lightshow.

I’ll look into the power FETs tonight :slight_smile:

Going to try to break through the clutter:

From the hardware side, all you want to do is turn a bunch of LEDs on and off.

  • How many LEDs need to be controlled individually?

  • How much current per LED. i.e., small 5mm LEDs or large 1 or 3W illumination LEDs?

https://www.superbrightleds.com/moreinf … s-x3/1465/

these look good. i would like to use 3 one foot sections. They use 1.8 watts a foot and are 12v.

also this little thing looks interestin … ucts/11214

OK, I re-read your post and I think I get what you’re trying to do. First, your question about the LED controlled by a serial control line, take a look at [this link, it explains how the LED is being controlled from a serial port flow control signal. The example you show is using the FTDI drivers and apparently their API. The same thing can be done (on Windows, anyway) by using the .NET SerialPort class or the Win32 serialcomm dlls. It works the same way whether the PC has a native serial port or you are using an off the shelf USB to Serial converter cable.

The reason your relay doesn’t switch is that the serial port can’t supply enough current. Further, this is a good way to damage the port! Don’t do it again :slight_smile:

You can switch those LEDs you linked to if you use the MOSFET breakout. Otherwise they need more current than the port can supply.

I don’t know if the serial flow lines can update at 60 times/second, though. Is that critical for your application?

[edit]

Forgot you’re doing this under Linux. I do have some code that does the same thing (twiddles serial control lines) using C++ on Linux but it’s too long to copy here.

I did an experiment with one of my boards: http://youtu.be/ewSaPodA53c

That’s a (not very good) video of it blinking a short green LED strip at 3 speeds: approximately 10 times/second, 3/second and 60/second. Unfortunately the higher speeds don’t display too well. I think the blink interferes with the video sample rate. And it’s a really crappy webcam :-(](http://www.cedarlakeinstruments.com/blog/archives/41)

lyndon:
I don’t know if the serial flow lines can update at 60 times/second, though. Is that critical for your application?

If he's recording 1's and 0's, w/1's indicating a beat, then his output rate has to match his input rate or else do some resampling scheme. I wonder if he wouldn't be better storing the time index of each beat.

Hey guys.

Originally I was hoping to get some sort of software PWM through the USB-Serial FTDI cable I have. I do not think this is going to work. I didn’t understand how PWM worked at first, I thought it was simply the rate of on and off, I guess it is the ratio between the two states.

Some how I will need to use a precomputed file to control 3 different PWM pins for 3 different LEDs. Someday I may want to add more LEDs on separate PWM pins…

I was looking at arduinos, there are a lot of them.

What would be the best MCU for this type of project?

I’m not against buying a new controller even though I already have a RaspPI.

As for the circuitry I am shamefully lost. I have the Make: Getting started with arduino book and also the Make: Electronics book I could review to learn the basics of a circuit. Maybe the hardware needed to implement this project isn’t so complicated?

I guess I’m a little confused about what you want to do. Are you trying to blink/flash LEDs or PWM them?

The difference is that flashing is just what it says; basically on or off at a certain rate. PWM changes the duty cycle of the power applied to the LED to make it brighter or dimmer. It’s not the same as flashing the LED. [This product will let you easily control LEDs on/off and blink them, but it does not do PWM.](http://www.cedarlakeinstruments.com/products/products.php#IOCTL232)

yeah pwm. rediculous right, sorry for the confusion.

I don’t know enough about the RPi to know if it can do PWM at an acceptable rate, but I doubt it would be easy to get high speed PWM.

Any of the Arduinos will generate PWM signals easily.

The RPi model I have has 1 PWM gpio pin. According to this thread http://www.raspberrypi.org/forums/viewt … 5&p=206762 I would need to implement software PWM over an arbitrary gpio pin if I wanted more PWM lines, which could introduce performance issues.

I’d rather have something that is guaranteed to work. I’m not tied up on implementing PWM over a USB-Serial cable anymore and am not against purchasing an arduino. I would like to see this through to completion.

This thread looks informative, I’m going to give it a read. :slight_smile:

http://m.instructables.com/id/PWM-an-RG … h-Arduino/

Is the following crazy - I want to control which PWM sequence the arduino will execute based on a wireless signal that is sent by my tablet and sent to the arduino.

I would do this for the sake of initiating the correct PWM sequence on the arduino while at the same time play the song. I know that I could write a custom media player (which maybe will send a packet of data or a specificly sized ping to the arduino?) on android… there is example code found on the internet for that. Probably the biggest issue would be getting the arduino to execute something when a signal is received. I see that the Arduino Yun has a wireless adapter built in. Have you ever thought about or seen something like this?

Well,l if you can get one channel of PWM from the pi, I’d say start with that and see how it goes instead of jumping into something bigger right away.

However, I’m still confused about the relationship between the 1’s & 0’s in the array and your PWM values.

lyndon:
However, I’m still confused about the relationship between the 1’s & 0’s in the array and your PWM values.

Me too. At some point you have to wonder if MIDI already does the job the OP intends to do and instead of re-inventing the wheel, he should learn more about MIDI and customize the Arduino to turn MIDI messages into the desired light show.

Writing an array of 1’s and 0’s was simply my way of trying to construct my own PWM functions, for fun. I can adjust the ratio of 1s and 0s to achieve the desired dimming effect right?

The idea is that when I learn how to write the sequence/ratio of on:off to create one pulse, I can then use this code/maths function to stretch/compress the duration of the pulse, cut the pulse short, maybe chop the pulse into 4ths where at each 4th I would zero the ‘on’ value for a split second to give sort of a staggered feel to the pulse.

If I can harness various functions that will properly write the ratio of 1 to 0 then I can begin to write a program that will insert these functions into an array at the press of a keyboard key. One of the first things I thought when I started this project was “Can I use some sort of Music Tracker, like Renoise(which is a really sweet program), to allow me to generate the digital signals i need” but I haven’t dug into this much yet.

Now that my project includes MCUs with PWM built in, I might be able to get the same functionality with less work, but I like math so I would actually have fun trying to create some program just by reading and making sense of the PWM wikipedia page or something.

I do have some ambitious plans for this, but we’ll see what happens.

My current train of thought is this, get my RPi to switch a mosfet(?) to control a 12v LED. I may need to get resistors idk, I have one of those 12v “AA” battery packs I can plug into my bread board easily.

Mee_n_Mac:

lyndon:
However, I’m still confused about the relationship between the 1’s & 0’s in the array and your PWM values.

Me too. At some point you have to wonder if MIDI already does the job the OP intends to do and instead of re-inventing the wheel, he should learn more about MIDI and customize the Arduino to turn MIDI messages into the desired light show.

Hi, I really like the idea of using midi to sequence the led pulse. I might play with this some day…

Here is what I came up with so far. The led blinks to the basic beat of the sound, it will change tempo, but most songs don’t have major tempo changes, atleast the ones i’ve ran through the ibt beat tracker

skip to 1:50 http://youtu.be/IqFEZBpSY6U

https://www.youtube.com/watch?v=A1YgZcksCH8

It runs off of a raspberry pi and performs software PWM off of a gpio pin. The code sets the light on and waits a certain number of milliseconds before it turns the light off and again waits a certain number of milliseconds. Although its no perfect since at a dim on:off ratio there is slight blinking. i’m not sure if this would be visible in the ambient light, but it is when i look directly at the bulb…

The led strip has built in resistors so i just hook up a battery to the led with a mostfet in between. I never understood why the raspberry pi has to also be grounded? to the mosfet? instead of just toggling the pin.

Just an update. I might post a link to the code or something if anyone is interested. Thanks!