... Mais par contre, elle est bien pratique pour alimenter mon sonar US URM37 si je voulais le connecter en I2C...
à condition que sa consommation n’excède pas les 300mA
Posté 23 août 2011 - 10:48
/*Arduio example code for MD23 and LCD03 using the wire and software Serial librarys*/
#include <SoftwareSerial.h>
#include <Wire.h>
#define md23Address 0x58 // Address of the MD22
#define softwareReg 0x0D // Byte to read the software version
#define speed1 0x00 // Byte to send speed to first motor
#define speed2 0x01 // Byte to send speed to second motor
#define cmdByte 0x10 // Command byte
#define mvCsr 0x02 // Command for LCD03 to move cursor
#define hideCsr 0x04 // Byte to hide LCD03 cursor
#define clrScrn 0x0C // Byte to clear LCD03 screen
#define encoderOne 0x02 // Byte to read motor encoder 1
#define encoderTwo 0x06 // Byte to read motor encoder 2
#define voltRead 0x0A // Byte to read battery volts
#define rxPin 2 // software serial rx pin
#define txPin 3 // software serial tx pin
SoftwareSerial lcd_03 = SoftwareSerial(rxPin, txPin); // Defines software serial port for LCD03
int x=0; // int x stores a value to be used as speed data for the motors
void setup(){
Wire.begin();
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
//lcd_03.begin(9600); // Begin serial for LCD03
Serial.begin(9600);
delay(100); // Wait for everything to power up
/*
lcd_03.print(clrScrn, BYTE);
lcd_03.print(hideCsr, BYTE);
lcd_03.print("MD23 Example V:");
int softVer = getSoft(); // Gets the software version of MD23
lcd_03.print(softVer, DEC); // Print software version to the screen
*/
Serial.print(clrScrn, BYTE);
Serial.print(hideCsr, BYTE);
Serial.print("MD23 Example V:");
int softVer = getSoft(); // Gets the software version of MD23
Serial.print(softVer, DEC); // Print software version to the screen
encodeReset(); // Cals a function that resets the encoder values to 0
}
void loop(){
x = 255; // Put a value of 255 in x, this will dive motors forward at full speed
do{ // Start loop to drive motors forward
Wire.beginTransmission(md23Address); // Drive motor 2 at speed value stored in x
Wire.send(speed2);
Wire.send(x);
Wire.endTransmission();
Wire.beginTransmission(md23Address); // Drive motor 1 at speed value stored in x
Wire.send(speed1);
Wire.send(x);
Wire.endTransmission();
encoder1(); // Calls a function that reads and displays value of encoder 1 to LCD03
encoder2(); // Calls a function that reads and displays value of encoder 2 to LCD03
volts(); // Calls function that reads and displays battery volts
if(encoder1() > 4500) // When value of encoder 1 is greater than 4500 put 138 in x to slow motor down
x = 138;
}while(encoder1() < 5000); // Loop untill encoder 1 is 5000 or more
stopMotor(); // Calls function to stop motors
delay(1000);
x = 0; // Put a value of 0 in x, this will drive motors at full reverse speed
do{ // Start loop to drive motors reverse
Wire.beginTransmission(md23Address); // Drive motor 2 at speed value stored in x
Wire.send(speed2);
Wire.send(x);
Wire.endTransmission();
Wire.beginTransmission(md23Address); // Drive motor 1 at speed value stored in x
Wire.send(speed1);
Wire.send(x);
Wire.endTransmission();
encoder1(); // Calls a function that reads and displays value of encoder 1 to LCD03
encoder2(); // Calls a function that reads and displays value of encoder 2 to LCD03
volts(); // Calls function that reads and displays battery volts
if(encoder1() < 500) // When value of encoder 1 is less than 500 put 118 in x to slow motor down
x = 118;
}while(encoder1() > 0); // Loop untill encoder 1 is 0 or less
stopMotor(); // Calls function to stop motors
delay(1000);
}
int getSoft(){ // Function that gets the software version
Wire.beginTransmission(md23Address); // Send byte to read software version as a single byte
Wire.send(softwareReg);
Wire.endTransmission();
Wire.requestFrom(md23Address, 1); // request 1 byte form MD23
while(Wire.available() < 1); // Wait for it to arrive
int software = Wire.receive(); // Read it in
return(software);
}
void encodeReset(){ // This function resets the encoder values to 0
Wire.beginTransmission(md23Address);
Wire.send(cmdByte);
Wire.send(0x20); // Putting the value 0x20 to reset encoders
Wire.endTransmission();
}
long encoder1(){ // Function to read and display value of encoder 1 as a long
Wire.beginTransmission(md23Address); // Send byte to get a reading from encoder 1
Wire.send(encoderOne);
Wire.endTransmission();
Wire.requestFrom(md23Address, 4); // Request 4 bytes from MD23
while(Wire.available() < 4); // Wait for 4 bytes to arrive
long firstByte = Wire.receive(); // Recieve 4 bytes highest byte first
long secondByte = Wire.receive();
long thirdByte = Wire.receive();
long fourthByte = Wire.receive();
long poss1 = (firstByte << 24) + (secondByte << 16) + (thirdByte << 8) + fourthByte; // Put them together
/*
lcd_03.print(mvCsr, BYTE);
lcd_03.print(21, BYTE); // Move cursor to space 21
lcd_03.print("Encoder 1 ");
lcd_03.print(poss1, DEC); // Print encoder 1 value to LCD03
lcd_03.print(" "); // Print some spaces to clear space after encoder value
delay(50); // Wait for everything to make sure everything is sent
*/
Serial.print(mvCsr, BYTE);
Serial.print(21, BYTE); // Move cursor to space 21
Serial.print("Encoder 1 ");
Serial.print(poss1, DEC); // Print encoder 1 value to LCD03
Serial.print(" "); // Print some spaces to clear space after encoder value
Serial.print("\n");
delay(50); // Wait for everything to make sure everything is sent
return(poss1); // returns value of encoder 1 position as a long
}
long encoder2(){ // Function to read and display velue of encoder 2 as a long
Wire.beginTransmission(md23Address); // Send byte to get a reading from encoder 2
Wire.send(encoderTwo);
Wire.endTransmission();
Wire.requestFrom(md23Address, 4); // Request 4 bytes from MD23
while(Wire.available() < 4); // Wait for 4 bytes to become available
long firstByte = Wire.receive(); // Get four bytes highest byte first
long secondByte = Wire.receive();
long thirdByte = Wire.receive();
long fourthByte = Wire.receive();
long poss2 = (firstByte << 24) + (secondByte << 16) + (thirdByte << 8) + fourthByte; // Put them together
/*
lcd_03.print(mvCsr, BYTE);
lcd_03.print(41, BYTE); // Move cursor to space 41
lcd_03.print("Encoder 2 ");
lcd_03.print(poss2, DEC); // Print value of encoder 2 position
lcd_03.print(" "); // Print some spaces to clear space after encoder value
delay(50); // Wait for everything to make sure everything is sent
*/
Serial.print(mvCsr, BYTE);
Serial.print(41, BYTE); // Move cursor to space 41
Serial.print("Encoder 2 ");
Serial.print(poss2, DEC); // Print value of encoder 2 position
Serial.print(" "); // Print some spaces to clear space after encoder value
delay(50);
return(poss2); // Returns encoder 2 position as a long
}
void volts(){ // Function to read and display battery volts as a single byte
Wire.beginTransmission(md23Address); // Send byte to read volts
Wire.send(voltRead);
Wire.endTransmission();
Wire.requestFrom(md23Address, 1); // Request 1 byte form MD23
while(Wire.available() < 1); // Wait for byte to arrive
int batteryVolts = Wire.receive(); // Get byte
/*
lcd_03.print(mvCsr, BYTE);
lcd_03.print(61, BYTE); // Move cursor to space 61
lcd_03.print("Battery v = ");
lcd_03.print(batteryVolts/10, DEC); // Print batery volts / 10 to give you the number of whole volts
lcd_03.print("."); // As arduino has truncates floating point numbers we print a . here to act as a decimal point
lcd_03.print(batteryVolts%10, DEC); // Prints Battery volts % 10 to give us the
*/
Serial.print(mvCsr, BYTE);
Serial.print(61, BYTE); // Move cursor to space 61
Serial.print("Battery v = ");
Serial.print(batteryVolts/10, DEC); // Print batery volts / 10 to give you the number of whole volts
Serial.print("."); // As arduino has truncates floating point numbers we print a . here to act as a decimal point
Serial.print(batteryVolts%10, DEC); // Prints Battery volts % 10 to give us the
delay(50); // Wait to make sure everything is sent
}
void stopMotor(){ // Function to stop motors
Wire.beginTransmission(md23Address);
Wire.send(speed2);
Wire.send(128); // Sends a value of 128 to motor 2 this value stops the motor
Wire.endTransmission();
Wire.beginTransmission(md23Address);
Wire.send(speed1);
Wire.send(128); // Sends a value of 128 to motor 1 this value stops the motor
Wire.endTransmission();
}
Posté 23 août 2011 - 11:04
Posté 24 août 2011 - 12:00
Bonsoir
Le code est très long (j'ai même pas vu les commentaires lors de ma première lecture).
Même si on indique une correction, comment être sûr que tu comprends et que tu sauras appliquer le conseil ?
Le problème vient de Software Serial qui essaie d'initialiser la commande avec un périphérique non connecté, donc il ne passe pas dans le reste du code. De toute façon trop complexe pour commencer par tester.
Posté 24 août 2011 - 09:33
Posté 24 août 2011 - 06:14
Apprendre...Plus j'en apprend plus je me rend compte que je ne sais rien. C'est effrayant...
BOB4, mon drone hélicoptère autonome d'intérieur http://heli.bot.free.fr/
BOB3, mon robot autonome d'intérieur avec WiFi + Foxboard Linux http://ze.bot.free.fr/
BOB5, robot bipède simulé, puis tentative de réalisation (fail)
Posté 24 août 2011 - 08:50
Bref, vous l'avez compris, j'aime la difficulté.
Posté 25 août 2011 - 06:05
Posté 25 août 2011 - 06:20
Mon site internet : http://ferdinandpiette.com/
Posté 25 août 2011 - 10:51
C'est bien sur la fréquence du PWM qui parfois deviens audible.
En effet, je ne vois pas comment une fréquence de PWM peut griller des carte contrôleurs.
Posté 26 août 2011 - 12:50
Posté 26 août 2011 - 06:47
Posté 26 août 2011 - 07:50
Malédiction du Créatif :
Plus vous avez d’idées et moins vous arrivez à les structurer.
Posté 26 août 2011 - 08:36
Bon Problème résolu. (je n'ai rien fais de particulier mais ce sifflement a disparu... Il y a parfois des choses qu'il est préférable d'ignorer si on ne veux pas devenir fou... ;
Sinon, Voila la 1ere vidéo de SAMU. Elle à été faite un peux à l'arrache. Donc ne m'en voulez pas pour sa piètre qualité d'image. Mais pas de caméra en ce moment. Elle est donc faite avec mon téléphone (qui m'aura décidément beaucoup servi cet an ci)
Donc voila Pour le moment un seul capteur
A l'approche d'un obstacle, le robot tourne à gauche pendant 100 millisecondes
Puis repart en avant.
Ce n'est bien sur qu'une 1ere vidéo donc qu'un 1er pas.
http://www.youtube.c...h?v=Adm-aW5MqCs
Cdlt
Posté 26 août 2011 - 10:22
Mon site internet : http://ferdinandpiette.com/
Posté 26 août 2011 - 10:35
Au passage :
A mon avis ton "signal sonore" venait du fait que tu ne mettais rien en sortie sur ta pin DIR. Dans le code tu la définissait juste comme OUTPUT mais tu ne la mettait ni high, ni low, ce qui fait que potentiellement elle etait a un état indéfini, donc peut etre qu'elle variait suivant les parasites, ce qui fait que ton moteur recevait des parasites.
Ce n'est qu'une supposition mais si maintenant les bruits ont disparus juste après qu'on rajoute les valeurs sur la pin DIR, ca pourrait bien etre ça.
0 members, 1 guests, 0 anonymous users