Archive for September, 2009

Fading LEDs – Circuit & Arduino Way

Posted by Erin, the RobotGrrl on Monday, September 7th, 2009

Someone recently commented on one of the posts and asked:

Hey Erin, I was just checking around looking for help with a project Im doing. Im not an expert by any means ,I could really use the help and expertise of somone like you. I like your robot too.
Im building a Terniator endo Bust. Its Recast vinyl kit. My …dilemma is ,…The kit came with 2 Red LEDs for the eyes,a bouble A battery pack and a switch. I want to mod this guy so the lights come on slowly,and when switched off they dim out.(3-5 sec.)
The second effect I want is to install a pulsing or vibrating motor inside the scull that comes on momentarily with the lights?
I have other Ideas too. If I can interest you ,Id be will to pay for your help.
I hope this sounds interesting to you, Thanks ,Daniel Shaffer

Sounds like a great weekend project!

There are two ways to solve this problem: with a circuit, or with a microcontroller.

I can’t exactly help out with the mathematical part of the circuit, but in order to obtain the dimming effects, you would need to first charge a capacitor up when you switch it on, that would be connected to the LEDs. As more and more voltage fills up into the capacitor, the LEDs will make a fade-in effect! When you switch off, the capacitor will have to de-charge (perhaps into a different capacitor). When it is emptying, the voltage will be going lower and lower, making a fade-out effect.

The second part of your question, how to make a vibrating motor come on with the lights… you would have to use a 555 timer IC. These also use capacitors and resistors in order to create a timed circuit. They are a really interesting concept, and I would encourage you to check out these sites about them! :D

Now… if you wanted to use a more extendable option with a microcontroller, that is more easier! I made a post about how to fade many LEDs here, with an Arduino. You could have the LEDs fading in and out while having the motor turning on/off. AND, you could use sensors to create specific behaviours and triggers for the Terniator.

I hope this answers your question, and I hope you will keep us posted on the status of your project! Woohoo for blinking LEDs!

Posted in: Other, Programming, Projects.

Friday Night Robotics – Visualizing Data w/Matlab

Posted by Erin, the RobotGrrl on Friday, September 4th, 2009

I recently purchased Matlab since it seems to be pretty popular on this campus, and I’m taking a part of a class on it. You didn’t really have to purchase Matlab though, since you could obtain it through different ways, or use a lab computer. My reasoning was that I wouldn’t want to be stealing from an industry that is computer science related, that’s kind of FAIL, LOL! =) Plus, I wouldn’t want people to steal my software! :P

This software is really cool! You can graph data extremely easily!!!

I did a quick search for Arduino and Matlab, and saw that there were some working results!

I used my Sanguino with the IR sensor to send data to Matlab.

I found some very useful starting code from here . I actually didn’t modify it too much as I was eager to see it run!

  1. /*
  2. *
  3. * Take IR sensor data from Sanguino and put it into Matlab!
  4. *
  5. * Original code comments:
  6. *   Accelerometer Sensor
  7. *   ——————–
  8. *
  9. *   Reads an 3-D accelerometer
  10. *   attached to three digital inputs and
  11. *   sends their values over the serial port;
  12. *   There exists an opposite code to read
  13. *   the values from MATLAB.
  14. *
  15. *   Modified by CARLOS AGELL
  16. *   (www.carlosagell.tk)
  17. *
  18. *   Original code by
  19. *   http://www.0j0.org
  20. *   copyleft 2005 K3 – Malmo University – Sweden
  21. *   @author: Marcos Yarza
  22. *   @hardware: Marcos Yarza
  23. *   @project: SMEE – Experiential Vehicles
  24. *   @sponsor: Experiments in Art and Technology Sweden, 1:1 Scale
  25. */
  26.  
  27. #include <Wire.h>
  28. #include "WProgram.h"
  29. void readAcceleration(int axe);
  30.  
  31. int ledPin = 13;
  32. int xaccPin = 0;
  33. int yaccPin = 1;
  34. int zaccPin = 2;
  35. int value = 0;
  36.  
  37.  
  38. void setup() {
  39. Serial.begin(9600); // Sets the baud rate to 9600
  40. pinMode(ledPin, OUTPUT);
  41. pinMode(xaccPin, INPUT);
  42. pinMode(yaccPin, INPUT);
  43. }
  44.  
  45.  
  46. /* (void) readAccelerometer
  47. * procedure to read the sensor, calculate
  48. * acceleration and represent the value
  49. */
  50. void readAcceleration(int axe){
  51. value = analogRead(axe);
  52.  
  53.  
  54. if (axe == xaccPin){
  55. Serial.print(‘X’, BYTE);
  56. }
  57. if (axe == yaccPin){
  58. Serial.print(‘Y’, BYTE);
  59. }
  60. if (axe == zaccPin){
  61. Serial.print(‘Z’, BYTE);
  62. }
  63.  
  64. Serial.print(value, DEC);
  65. Serial.print(‘ ‘, BYTE);
  66.  
  67. }
  68.  
  69. void loop() {
  70. readAcceleration(xaccPin); //reads and represents acceleration X
  71. digitalWrite(ledPin, HIGH);
  72. delay(1200);
  73. digitalWrite(ledPin, LOW);
  74. }

The matlab code was also from this site, but I commented out a few lines so that there was only one graph line.

  1. %Graph Accelerometer Data
  2.  
  3. s = serial(‘/dev/tty.usbserial-FTE4Z66C’);
  4. set(s,‘BaudRate’,9600);
  5. set(s,‘DataBits’,8);
  6. set(s,‘StopBits’,1);
  7. fopen(s);
  8.  
  9. out =‘a’
  10. figure
  11. hold on    % on keeps all the current plot data, off resets the axes before drawing
  12. xacc =[];
  13. yacc =[];
  14. zacc =[];
  15. for i = 1 : 5000
  16.     out = fscanf(s);
  17.     if(sum(size(out))>0)
  18.         out2 = reshape(out(1:(round(size(out,2)/5)-1)*5),[5 (round(size(out,2)/5)-1)]);
  19.         out2 = out2‘;
  20.        out2 = str2double(out2(1:end,2:end));
  21.        if out(1) == sprintf(‘X‘)
  22.            xacc = [xacc out2(1:3:end)'];
  23.             plot(xacc);
  24.             %yacc = [yacc out2(2:3:end)'];
  25.            %plot(yacc,’r‘);
  26.            %zacc = [zacc out2(3:3:end)’];
  27.             %plot(zacc,‘g’);
  28.         end
  29.         drawnow
  30.     end
  31. end
  32.  
  33.  
  34. fclose(s)
  35. delete(s)
  36. clear s

It works okay, but it’s really slow. Even though the data is being sent every 1.2 seconds, it takes Matlab 10 seconds to plot it! Also, it kept saying this in the command window:


Friday Night Robotics - Data in Matlab

The graph looked like this in the end:


Friday Night Robotics - Data in Matlab

It was pretty exciting to see it being plotted!!

I think what is making it slow is that the data is being stored in an array/matrix, and then the lines are calculated, and then they are plotted.

What I want to do is just have a 3D graph of the IR sensor data over time. It doesn’t have to be a complete history, maybe just the past 10 values. I would also want the delay to be minimal, 100ms at most!

I have no idea how to do this yet, but I’m guessing playing around with that weird out2 variable would be a start. Rewriting the code the way I want it would also be a good place to start, because then I can understand everything that’s going on :D

Oh yeah, and the day I received Matlab was the day the newer version came out that supports 64 bit for Macs. :( but at least I have the second-latest version of the software. :)

There are also these ‘add-ons’ for Matlab called toolboxes. There are gajillions out there for HMMs, Bayes logic, AI, Robotics (Kinematics), Probability, Neural Nets, and sooo much more. I wonder if there is a toolbox for determining the proper ratio of icing to a cupcake though? That would be extremely useful, I should probably make that :P :D

The benefit this has over using Processing to visualize data is that it’s very more robust and mathematical. However, if one wanted to make an art display, Processing would win hands down.

Posted in: Programming, Projects.