Show Posts
|
|
Pages: [1]
|
|
4
|
Using Arduino / Programming Questions / Using more than 3 servos in Arduino MEGA 2560
|
on: March 06, 2013, 08:26:57 pm
|
Hello guys, I'm making a project that converts each char from a string (received by a Bluetooth module) to servos positions. #include <Servo.h> String frase=0; char c; int x=0; int angulo = 19; //Determina o angulo equivalente da anguloição zero. Vai de 1 a 180. int num_caract = 5; //Ajusta o programa ao número de caracteres que são mostrados por vez. int pos = 0;
int ascii[100]; Servo a1; Servo a2; Servo b1; Servo b2; Servo c1; Servo c2; Servo d1; Servo d2; Servo e1; Servo e2;
byte pa1 = 49; byte pa2 = 51; byte pb1 = 45; byte pb2 = 47; byte pc1 = 41; byte pc2 = 43; byte pd1 = 37; byte pd2 = 39; byte pe1 = 33; byte pe2 = 35; boolean debug = 0;
void setup(){ biblioteca(); //Inicia os valores da biblioteca. zerarServo(); a1.attach(pa1); a2.attach(pa2); b1.attach(pb1); b2.attach(pb2); c1.attach(pc1); c2.attach(pc2); d1.attach(pd1); d2.attach(pd2); e1.attach(pe1); e2.attach(pe2); pinMode(13,OUTPUT); Serial.begin(9600); Serial1.begin(38400); Serial1.print("AT+RESET \r\n"); Ler(); Serial1.print("AT+UART=115200,0,0"); Ler(); Serial1.begin(115200); Serial1.print("AT+ORGL \r\n"); Ler(); Serial1.print("AT+NAME=dispositivobraille \r\n"); Ler(); Serial1.print("AT+INIT \r\n"); Ler(); Serial1.print("AT+INQ \r\n"); Ler(); Serial.println("PRONTO!"); } void loop(){ //Comunicação Android->Arduino: if(frase==0){ while(Serial1.available()){ c=Serial1.read(); frase = String(frase + c); x=1; digitalWrite(13,HIGH); } delay(100); if(x==1){ Serial.println(frase); zerarServo(); imprimirBraille(); frase = 0; x=0; digitalWrite(13,LOW); } } //Comunicação Arduino->Android: if(frase==0){ while(Serial.available()){ c=Serial.read(); frase = String(frase + c); x=1; digitalWrite(13,HIGH); } delay(100); if(x==1){ Serial1.println(frase); frase = 0; x=0; digitalWrite(13,LOW); } } } void Ler(){ String Comando; while (Serial.available()) { if (Serial.available() >0) { char c = Serial.read(); Comando += c; } } if (Comando.length() >0) { Serial.print(Comando); } delay(500); } void imprimirBraille(){ int y; int colesq = 0; int coldir = 0; int ciclo; int paginas = 1; for(y=0; y<5; y++){ Serial.println(frase[y]); bitWrite(colesq,0,bitRead(ascii[frase[y+(num_caract*ciclo)]-32],0)); bitWrite(colesq,1,bitRead(ascii[frase[y+(num_caract*ciclo)]-32],1)); bitWrite(colesq,2,bitRead(ascii[frase[y+(num_caract*ciclo)]-32],2)); bitWrite(coldir,0,bitRead(ascii[frase[y+(num_caract*ciclo)]-32],3)); bitWrite(coldir,1,bitRead(ascii[frase[y+(num_caract*ciclo)]-32],4)); bitWrite(coldir,2,bitRead(ascii[frase[y+(num_caract*ciclo)]-32],5)); Serial.println(colesq); Serial.println(coldir); Serial.println(); switch (y){ case 0: a1.write(angulo*coldir); a2.write(angulo*colesq); break; case 1: b1.write(angulo*coldir); b2.write(angulo*colesq); break; case 2: c1.write(angulo*coldir); c2.write(angulo*colesq); break; case 3: d1.write(angulo*coldir); d2.write(angulo*colesq); break; case 4: e1.write(angulo*coldir); e2.write(angulo*colesq); break;
} } delay(100); }
void biblioteca(){ //+32 ascii[0] = 0; ascii[65] = 1; //'a'; ascii[66] = 3; //'b'; ascii[67] = 9; //'c'; ascii[68] = 25; //'d'; ascii[69] = 17; //'e'; ascii[70] = 11; //'f'; ascii[71] = 27; //'g'; ascii[72] = 19; //'h'; ascii[73] = 10; //'i'; ascii[74] = 26; //'j'; ascii[75] = 5; //'k'; ascii[76] = 7; //'l'; ascii[77] = 13; //'m'; ascii[78] = 29; //'n'; ascii[79] = 21; //'o'; ascii[80] = 15; //'p'; ascii[81] = 31; //'q'; ascii[82] = 23; //'r'; ascii[83] = 14; //'s'; ascii[84] = 30; //'t'; ascii[85] = 37; //'u'; ascii[86] = 39; //'v'; ascii[87] = 52; //'w'; ascii[88] = 45; //'x'; ascii[89] = 61; //'y'; ascii[90] = 53; //'z'; ascii[33] = 1; //'a'; ascii[34] = 3; //'b'; ascii[35] = 9; //'c'; ascii[36] = 25; //'d'; ascii[37] = 17; //'e'; ascii[38] = 11; //'f'; ascii[39] = 27; //'g'; ascii[40] = 19; //'h'; ascii[41] = 10; //'i'; ascii[42] = 26; //'j'; ascii[43] = 5; //'k'; ascii[44] = 7; //'l'; ascii[45] = 13; //'m'; ascii[46] = 29; //'n'; ascii[47] = 21; //'o'; ascii[48] = 15; //'p'; ascii[49] = 31; //'q'; ascii[50] = 23; //'r'; ascii[51] = 14; //'s'; ascii[52] = 30; //'t'; ascii[53] = 37; //'u'; ascii[54] = 39; //'v'; ascii[55] = 52; //'w'; ascii[56] = 45; //'x'; ascii[57] = 61; //'y'; ascii[58] = 53; //'z'; ascii[16] = 26; //'0'; ascii[17] = 1; //'1'; ascii[18] = 3; //'2'; ascii[19] = 9; //'3'; ascii[20] = 25; //'4'; ascii[21] = 17; //'5'; ascii[22] = 11; //'6'; ascii[23] = 27; //'7'; ascii[24] = 19; //'8'; ascii[25] = 10; //'9'; ascii[1] = 22; //'!'; ascii[2] = 38; //'"'; ascii[4] = 48; //'''; ascii[7] = 2; //'''; ascii[8] = 55; //'('; ascii[9] = 62; //')'; ascii[10] = 20; //'*'; ascii[12] = 2; //','; ascii[13] = 36; //'-'; ascii[14] = 4; //'.'; ascii[26] = 9; //':'; ascii[27] = 6; //';'; ascii[29] = 54; //'='; ascii[31] = 34; //'?'; ascii[59] = 42; //'['; ascii[60] = 51; //'\'; ascii[61] = 59; //']'; ascii[63] = 56; //'_'; ascii[3] = 60; //'#' - sinal de algarismo; ascii[62] = 40; //'^' - sinal de maiusculo; }
void zerarServo(){ a1.write(0); a2.write(0); b1.write(0); b2.write(0); c1.write(0); c2.write(0); d1.write(0); d2.write(0); e1.write(0); e2.write(0); } The program is working very well with 1, 2 and 3 servos. But when I connect the fourth servo, all servos stop working properly, not responding to .write() function. I intend to use 10 servos, and I made a project before that used 12 servos... so it's kinda strange O.o Arduino is connected in the USB port, and the servos are using an external source of 800mA of max. current. 4.5V. Both GNDs are connected. I'm not using interruptions, or timers. Help plz!
|
|
|
|
|
5
|
Using Arduino / Networking, Protocols, and Devices / Re: ICOMSat Sim900 / Mega2560
|
on: March 03, 2013, 02:52:09 am
|
Well, check if you're connecting RX and TX to their correspondent in the shield. Also check if the baudrate of your script is the same used by the shield. (if you don't know what is that, google it ) I ran into this problem very early in my project, but I don't really remember how I got it solved... Just try the above and gimme feedback ok? 
|
|
|
|
|
6
|
Using Arduino / Networking, Protocols, and Devices / Re: ICOMSat Sim900 / Mega2560
|
on: February 02, 2013, 09:17:40 pm
|
|
It uses power from arduino. I recommend you check if the library is compatible with your arduino and with other components you're going to use. My project became much more complicated because after I done what I mentioned above, the receiving script stopped working properly, so I had to reprogram it. And I turned into a slow script, that took around 3 seconds to verify if a message arrived... it was a problem because the user was going to press a button just to verify if the message arrived. If you can afford to buy a more expensive but compatible shield, do it.
|
|
|
|
|
10
|
Using Arduino / Networking, Protocols, and Devices / Re: ICOMSat Sim900 / Mega2560
|
on: August 29, 2012, 02:47:16 pm
|
Hey, GOOD news! I had the amazing idea of opening the GSM_Shield.cpp and change all the "mySerial" for "Serial1", and deleting all the #include NewSoftSerial By doing this, I just changed the comunication to Serial1 (pins 18 and 19) of MEGA, so I jumped the RX to the TX to these pins aaaaaand... the results are the following: system startup no call no call no call ...And when I called the shield from my cellphone: incoming voice call from xxxxxxxxx (my number) YES, it's working!! I'm so happy!!  That's it my friends!
|
|
|
|
|
12
|
Using Arduino / Networking, Protocols, and Devices / Re: ICOMSat Sim900 / Mega2560
|
on: August 28, 2012, 03:43:38 pm
|
|
Thanks sTrider, now I'm having the same problems as you. I've noticed that even with no jumpers in the tx/rx the library keeps giving those advices:
no response Received SMS from (sim position: 65534)
So the arduino is not comunicating with the shield. Probably something about the pins.
|
|
|
|
|
13
|
Using Arduino / Networking, Protocols, and Devices / Re: ICOMSat Sim900 / Mega2560
|
on: August 27, 2012, 02:37:41 pm
|
|
Hi, I'm using IcomSat and Mega 2560 too, and I'm having some issues to make arduino comunicate with the shield. Here is what I get when using the example GSM_GPRSLibrary_AT:
GSM Shield testing. DB:NO RESP DB:NO RESP DB:NO RESP ERROR: SIM900 doesn't answer. Check power and serial pins in GSM.cpp
status=IDLE
Right now, I'm using pins 4 and 5 at the UART (already tried 2 and 3) and the switch is at UART_port. The SIM900 library don't allow me to change its pins. And the GSM_Shield library is full of errors. What library did you use? Please tell me how you connected the shield and the arduino. What pins you used in the multiplexer? Thanks in advance.
|
|
|
|
|