0
Offline
Tesla Member
Karma: 50
Posts: 6533
Arduino rocks
|
 |
« Reply #15 on: July 09, 2011, 10:39:42 am » |
what i am to send at your code in order for me to trigger a specific servo.. im not going to be sending servo positions, il only be sending a specific character then my receiver arduino would process it. I would think you could use a series of "if" or "case" statements to evaluate the character received by the arduino, and send a value to the appropriate servo based on the received character.
|
|
|
|
|
Logged
|
|
|
|
|
Philippines
Offline
Newbie
Karma: 0
Posts: 25
|
 |
« Reply #16 on: July 09, 2011, 12:37:41 pm » |
ok! will try that..thanks!!
|
|
|
|
|
Logged
|
|
|
|
|
Philippines
Offline
Newbie
Karma: 0
Posts: 25
|
 |
« Reply #17 on: July 12, 2011, 11:12:06 am » |
@zoomkat im not getting anything out of the serial monitor, also my servos wont run. thanks! P.S. im using a PIC16F628A as my transmitter programmed using flowcode v4 and arduino decimilla 168 as my receiver. over 5812A UHF transceiver. http://www.e-gizmo.com/KIT/images/UHF/5812A%20Tech%20Manual.pdf
|
|
|
|
« Last Edit: July 13, 2011, 11:24:25 am by pao_wikhan »
|
Logged
|
|
|
|
|
Philippines
Offline
Newbie
Karma: 0
Posts: 25
|
 |
« Reply #18 on: July 15, 2011, 10:37:34 am » |
can someone help me recode my code???im not getting any results, even for just one servo port via serial comm. i dont get it, why i can let an LED be high but moving a servo, i cant..help pls! tnx! Some servo test code I use for testing two servos: // zoomkat 11-22-10 serial servo (2) test // for writeMicroseconds, use a value like 1500 // for IDE 0019 and later // Powering a servo from the arduino usually DOES NOT WORK. // two servo setup with two servo commands // send eight character string like 15001500 or 14501550
#include <Servo.h> String readString, servo1, servo2; Servo myservo1; // create servo object to control a servo Servo myservo2;
void setup() { Serial.begin(9600); myservo1.attach(6); //the pin for the servo control myservo2.attach(7); Serial.println("servo-test-21"); // so I can keep track of what is loaded }
void loop() {
while (Serial.available()) { delay(1); if (Serial.available() >0) { char c = Serial.read(); //gets one byte from serial buffer readString += c; //makes the string readString } }
if (readString.length() >0) { Serial.println(readString); //see what was received // expect a string like 07002100 containing the two servo positions servo1 = readString.substring(0, 4); //get the first four characters servo2 = readString.substring(4, 8); //get the next four characters Serial.println(servo1); //print to serial monitor to see results Serial.println(servo2); int n1; //declare as number int n2; char carray1[6]; //magic needed to convert string to a number servo1.toCharArray(carray1, sizeof(carray1)); n1 = atoi(carray1); char carray2[6]; servo2.toCharArray(carray2, sizeof(carray2)); n2 = atoi(carray2); myservo1.writeMicroseconds(n1); //set servo position myservo2.writeMicroseconds(n2); readString=""; } }
i get your code now...im using 3 servos so i have to change this char carray1[6]; to char carray1[9]; ???am i right????
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Online
Brattain Member
Karma: 137
Posts: 19003
I don't think you connected the grounds, Dave.
|
 |
« Reply #19 on: July 15, 2011, 11:28:46 am » |
im using 3 servos so i have to change this char carray1[6]; to char carray1[9]; ???am i right???? Not sure I follow your logic there - can you post your code?
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
0
Offline
Tesla Member
Karma: 50
Posts: 6533
Arduino rocks
|
 |
« Reply #20 on: July 15, 2011, 11:29:35 am » |
i get your code now...im using 3 servos so i have to change this char carray1[6]; to char carray1[9]; ???am i right???? No, you don' get the code. Note that a seperate array is used for each servo. This is just one very basic way of controlling several servos with the servo positions being sent in a single string. There are code improvements once you decide how you are to control the arm.
|
|
|
|
|
Logged
|
|
|
|
|
Philippines
Offline
Newbie
Karma: 0
Posts: 25
|
 |
« Reply #21 on: July 16, 2011, 06:00:20 am » |
why is the array 6???that is whow i dont get it..but i did manage to add a third servo by copying the pervious code for the third..why is carray[6]? the comment just stated that it is where the magic happens..
as i send $130130020 on the serial monitor the servos move to that specific degree..
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Online
Brattain Member
Karma: 137
Posts: 19003
I don't think you connected the grounds, Dave.
|
 |
« Reply #22 on: July 16, 2011, 06:17:10 am » |
why is the array 6??? Because an "int" can't store more than five decimal digits.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Philippines
Offline
Newbie
Karma: 0
Posts: 25
|
 |
« Reply #23 on: July 16, 2011, 07:59:16 am » |
why cant i use my hyper terminal to this???is this just for arduino serial monitor???
when i type in 90, it sends out
9 0
but in serial monitor i use $090, it sends $ 090
why is this?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Online
Brattain Member
Karma: 137
Posts: 19003
I don't think you connected the grounds, Dave.
|
 |
« Reply #24 on: July 16, 2011, 09:01:30 am » |
Because the serial monitor sends all the characters you type in only when you hit the send key, but hyperterm sends them as you press the individual keys.
(What is wrong with your question-mark key? Is it sticking down?)
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
0
Offline
Tesla Member
Karma: 50
Posts: 6533
Arduino rocks
|
 |
« Reply #25 on: July 16, 2011, 01:07:07 pm » |
why is the array 6??? Because you will need to store four bytes and a null terminator in the array for a total of 5 spaces required (as I understand it). I made the array capable of holding six places just to ensure sufficient array space while tinkering with the code. You should be able to use 5 instead of 6 as you should not have to send more than four characters for use with the servo library.
|
|
|
|
|
Logged
|
|
|
|
|
Philippines
Offline
Newbie
Karma: 0
Posts: 25
|
 |
« Reply #26 on: July 16, 2011, 10:59:36 pm » |
why is the array 6??? Because you will need to store four bytes and a null terminator in the array for a total of 5 spaces required (as I understand it). I made the array capable of holding six places just to ensure sufficient array space while tinkering with the code. You should be able to use 5 instead of 6 as you should not have to send more than four characters for use with the servo library. ohh. now i get it, i didnt get that it was like that. for every substring with 4 integers you allocated 6 spaces, but what is received is only 5 this was a safe precaution to the code. thanks! i'll put it back to 6 and not 9. thanks zoomkat!
|
|
|
|
|
Logged
|
|
|
|
|
Philippines
Offline
Newbie
Karma: 0
Posts: 25
|
 |
« Reply #27 on: July 18, 2011, 06:03:43 am » |
hi zoomkat,
i was able to control and see the results from the serial monitor. but when i connect the UART of the chip to the controller, it simply shows weird outputs. why is that?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Online
Brattain Member
Karma: 137
Posts: 19003
I don't think you connected the grounds, Dave.
|
 |
« Reply #28 on: July 18, 2011, 06:26:31 am » |
but when i connect the UART of the chip to the controller, Because the controller is a RS232 device with different levels and an inversion?
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Philippines
Offline
Newbie
Karma: 0
Posts: 25
|
 |
« Reply #29 on: July 18, 2011, 08:52:06 am » |
i get it now...what im receiving are the extended ascii codes, why is this?
|
|
|
|
|
Logged
|
|
|
|
|
|