sábado, 8 de febrero de 2014

Oscilador lineal

el siguiente programa controla el motor DC de una impresora a través de la señal de un potenciómetro

const int LeftAnalogOutPin = 9;
const int RightAnalogOutPin = 10;
int outputValue = 0;
int TiempoQueDuraLaCondicion =1;
//int Incrementos=8;
int sensorPin=A0;
int sensorValue=0;

void setup() { }
void loop() {
  sensorValue = analogRead(sensorPin);
  int Incrementos=map(sensorValue,0,1023,2,10);
  for (int thisPin = 41; thisPin <= 255; thisPin+=Incrementos+1) {
    outputValue = thisPin;
    analogWrite(LeftAnalogOutPin,outputValue);  
    delay(TiempoQueDuraLaCondicion);                
  }
   for (int thisPin = 255; thisPin >= 1; thisPin-=Incrementos) {
    outputValue = thisPin;
    analogWrite(LeftAnalogOutPin,outputValue);  
    delay(TiempoQueDuraLaCondicion);
  }
  analogWrite(LeftAnalogOutPin,0);
  for (int thisPin = 41; thisPin <= 255; thisPin+=Incrementos+2) {
    outputValue = thisPin;
    analogWrite(RightAnalogOutPin,outputValue);  
    delay(TiempoQueDuraLaCondicion);                
  }
  for (int thisPin = 255; thisPin >= 1; thisPin-=Incrementos) {
    outputValue = thisPin;
    analogWrite(RightAnalogOutPin,outputValue);  
    delay(TiempoQueDuraLaCondicion);
  }                  
  analogWrite(RightAnalogOutPin,0);
}

domingo, 2 de febrero de 2014

DC Motor controlled by Arduino UNO - speed ramp and reversing rotation

The Arduino program shown below let us change angular speed and reverse rotation to a little DC motor removed from a DeskPrinter.
For controlling the sense of rotation I used an H-Bridge, L293NE, who requires high speed diodes (SES5001) for being protected from motor's coils intensity. Anyway, I didn't find such high speed diodes (100ns=trr) so I used the 1N4007; but as the DC Motor is turning free, without any mechanical charge, I believe the response from DC motor internal coil is not doing any damage to the IC.

From datasheet, the diagram is mounted as follows. The blue areas have not been connected:
The whole system has been tested on a breadboard as shown on the picture.

The program developed directly in a easy and confortable way is as follows. The analog ouputs used from Arduino UNO are 9 and 10. The angular speed is controlled through PWM outputs.
The acceleration when turning is reached through increments on the for loop i.e.+=1
Furthermore, the delay on each loop inside the for structure decrease the angular acceleration linked directly to the increments +=1 referred before.
The initial value to be "written" when increasing from speed 0 rad/s should be greater than 1, as it has been experienced the motor doesn't starts to move until the value is more than 30. This value is still low, so I write a 41...

const int LeftAnalogOutPin = 9; 
const int RightAnalogOutPin = 10; 
int outputValue = 0;       
void setup() { }
void loop() {
  for (int thisPin = 41; thisPin < 255; thisPin+=1) { 
    outputValue = thisPin;
    analogWrite(LeftAnalogOutPin,outputValue);   
    delay(50);                  
  }
   for (int thisPin = 255; thisPin >= 1; thisPin-=1) { 
    outputValue = thisPin;
    analogWrite(LeftAnalogOutPin,outputValue);   
    delay(50); 
  }
  analogWrite(LeftAnalogOutPin,0);
  for (int thisPin = 41; thisPin < 255; thisPin+=1) { 
    outputValue = thisPin;
    analogWrite(RightAnalogOutPin,outputValue);   
    delay(50);                  
  }
  for (int thisPin = 255; thisPin >= 1; thisPin-=1) { 
    outputValue = thisPin;
    analogWrite(RightAnalogOutPin,outputValue);   
    delay(50); 
  }                   
  analogWrite(RightAnalogOutPin,0);
}

The next video shows how everything was mounted and the DC motor turning.


domingo, 19 de enero de 2014

Little Car on a table

On this post it is going to be planned a little car-robot who moved on a flat table and once it arrives to the border, it turns and go forward.

the objective is to sweep the table surface moving as per internally programed algorithm.

http://ssv.epfl.ch/files/content/sites/lben/files/users/179705/Brownian%20Motion%20Handout.pdf
http://bringerp.free.fr/Files/Captain%20Blood/Saupe87d.pdf


From Arduino Serial Port to be read by Matlab

Taking some data from Arduino AnalogRead but sending to serial port with two decimal after scaling from 1023 end-scale to 5V real-end-scale

so, the sketch in Arduino is:

int sensorA;
float sensorA1;

void setup()

{
  
  Serial.begin(9600);  // sets the serial port to 9600
}


void loop()

{
  sensorA = analogRead(0);
  sensorA1=(float)sensorA/1023*5;
  Serial.println(sensorA1); 
  delay(20);                      // wait 20ms for next reading
}


the objective is getting data from Arduino for being displayed on Matlab.


For openning the Serial Port from Matlab...

s = serial('COM6');
set(s,'BaudRate',9600);
fopen(s);
out = fscanf(s);
fclose(s)
delete(s)
clear s

the problems:
1) if MATLAB is run before Arduino connection, then Arduino found COM6 busy and it is not able to be connected
2) if Arduino get the COM6, the MATLAB find it busy and it is not able to connect and getting data from COM6

??? Error using ==> fopen
Port: COM6 is not available. Available ports: COM7.
Use INSTRFIND to determine if other instrument objects are connected to the requested device.

>> 

seems the project is blocked at this time.

MATLAB runs an old version 6.5.0, but I think no later version is required for this single application


Next solution steps to be checked:

http://www.mathworks.co.uk/matlabcentral/fileexchange/32374-matlab-support-package-for-arduino-aka-arduinoio-package

getting data from Excel

http://www.mrexcel.com/forum/excel-questions/488335-receive-data-com-port.html

from Excel 2007
http://strokescribe.com/en/read-serial-port-excel-2007.html
http://robottini.altervista.org/arduino-and-real-time-charts-in-excel