What you should do is power the servo with an external source, the arduino should just send the commands. In practice, plug the servo power pin and ground to a power source, and the servo command pin and ground to the arduino.
this is also another way that i am thinking of. But i need another power source..the external power source u mean is battery?because i wish to make a easier carry and mobility sensor...hope my sensor will not be too much stuff on top. Is that mean i need to use another 1 arduino board? Any more suggestion is appreciate...really need help here....
//convert read values to degrees -90 to 90 - Needed for atan2 int xAng = map(xRead, minVal, maxVal, 0, 180); int yAng = map(yRead, minVal, maxVal, 0, 90); int zAng = map(zRead, minVal, maxVal, 0, 90);
//Caculate 360deg values like so: atan2(-yAng, -zAng) //atan2 outputs the value of -π to π (radians) //We are then converting the radians to degrees x = RAD_TO_DEG * (atan2(yAng, zAng)); y = RAD_TO_DEG * (atan2(xAng, zAng)); z = RAD_TO_DEG * (atan2(yAng, xAng));
To convert to degree and match with servo motor range. I remap it to become 0-180 for x, 0-90 for y and 0-90 for z. But now the problem i met is when i use more than 1 servo motor, the reading will become unstable...may i know why? when i am using 1 servo motor. It works well. I can control the servo motor with sensor. (although not exact accurate angle). But when i connect 2 servo motor. The data will become negative values...is it be power supplied problem?all the Vcc and Gnd is connected with same pin. That is 3V3.
Hi all before that i am using ADXL345 eval board. Because of the communication problem between the eval board and arduino. I give up on the eval board and change to breakoutboard ADXL335. The before posting is: http://arduino.cc/forum/index.php/topic,95980.0.html
Objective: 1. the sensor is placed on wrist. The movement of the wrist is transfer to the Arduino Uno board and process and then send the output to servo motor. 2. 3 servo motors are used to control each axis. (x,y,z)
Here is what i had in my code:
Servo myservo; // create servo object to control a servo // a maximum of eight servo objects can be created Servo myservo1; Servo myservo2;
const int xPin = 0; const int yPin = 1; const int zPin = 2;
//The minimum and maximum values that came from //the accelerometer while standing still //You very well may need to change these int minVal = 262; int maxVal = 402;
//to hold the caculated values int x = 0; int y = 0; int z = 0;
//read the analog values from the accelerometer int xRead = analogRead(xPin); int yRead = analogRead(yPin); int zRead = analogRead(zPin);
//convert read values to degrees -90 to 90 - Needed for atan2 int xAng = map(xRead, minVal, maxVal, -90, 90); int yAng = map(yRead, minVal, maxVal, -90, 90); int zAng = map(zRead, minVal, maxVal, -90, 90);
//Caculate 360deg values like so: atan2(-yAng, -zAng) //atan2 outputs the value of -π to π (radians) //We are then converting the radians to degrees x = RAD_TO_DEG * (atan2(-yAng, -zAng) + PI); y = RAD_TO_DEG * (atan2(-xAng, -zAng) + PI); z = RAD_TO_DEG * (atan2(-yAng, -xAng) + PI);
delay(100);//just here to slow down the serial output - Easier to read }
Question: 1. according to the code, converting method to degree can be modified or not? 2. After tested the code with servo motor, the servo motor will move randomly (seem like messy output but it gives no problem in serial monitor) 3. Any1 can advised me how to works on this moving algorithm? many thanks for those who replied. Many thaks
In the light of all those quoted statements(it's been a hard time understanding all that ) i think you are not using the serial tx/rx uart ports and going to this method of posting in a text file because you can't get the whole values from the accelerometer (adxl) which are like 355, 456 and you are getting single values '7' ? is this the problem ? then ustilising the packet's will solve it.
Hi Nishant, sorry to make u confuse. The purpose of this thread is to ask how to send the data from test file in pc to arduino. It is because i have the data from eval board ADXL345. Then, Udo Klein ask me why i am not direct connect arduino to eval board ADXL345. So i am explained what is the problem that i am facing.
About Serial.write("7") is the example that i am going to test whether the data is sending out from arduino by using Serial communication. If i direct connect arduino to eval board. The data cant send/receive to/from eval board.
If i use hyperterminal in pc (connect eval board to PC), the reading i get is in the format : X:ff01 Y:0023 Z:ff11 So my perception is that: i hope i can replaced PC to Arduino and received the data from eval board. But i failed to do it.
And now i change another way round, get the data and stored in a txt file in pc first. Then, only transfer the file to arduino.
Hope you can understand. Really so appreciate your time here thanks
The eval board has a pair of serial pins. Can you not make use of those?
HI thanks for ur replied. I tried make use of those TX and RX at the eval board as well. I try before to declare the pin at arduino RX to receive the input from TX on Eval board but the reading is something just like a current electric value, not the position value for those 3 axis. From the beginning till now, i search through many information about this eval board but it is less. So i do hope that can discuss with you all here.
Mr.johnwasser suggested that my eval board is not suitable to connect direct to arduino since the pin mapping in the eval board already used up for another purpose. The only 1 possible way is using USB direct connect to arduino uno. But i faced another problem that arduino cant even been activated (maybe not recognize the eval board) when i connect directly Uno to eval board. For example, a simple code Serial.write("7"). Suppose the Tx led on Uno will be light up if data sent. But when i connect it to eval board. It is no light up at all. The data cant sent.
So i try another way, save the data to a text file and then transfer it to arduino. PC as intermediate medium. I really hope that i could find someone to help me out to hear my problem....
Sorry for my english if anywhere make you trouble to read this. Thanks
It might be good to Explain the big picture on what you are trying to do. With windows you can send a file to the com port using a simple batch file like below.
type hotpix.jpg >com5
ok basically i am using a eval board of adxl345 sensor. I can stored the value to a txt file in my PC. Then i have to send the data in the txt file to arduino to control a servo motor. So since the data is read line by line in each line as i describe previously. How i going to stored each axis value to a variable?
You can not use it to send a text file as a whole unit to Arduino, but you can use it to send a line at a time from a text file.
Check the documentation page 26.
Hi i also done it with given downloadtest.pde in sample folder...able to print it at the gobetwino ....but i have to store it into a variable for further calculation...is it possble"?? for example in a line i have : x:ff22 y:f00ef z:ff23
can i stored a = ff22, b= 00ef c=ff23? can i make something like this??? Let's say i have 100 lines with different value....
If you want to automatically transmit it this is the way to go. If you want to copy it manually you could use the serial monitor. If you are satisfied to transmit it statically you could compile it into your program. Until you explain clearly what you want to achieve more specific advice is close to impossible.
Maybe the GoBetwino will fit you bill but unless you get more specific nobody can tell you.
Now i am just a beginner to face with whatever i am working on. These kind of stuff is strange for me...so i need some example to start...after searching the information that you provided...it is seem like less what i had found regarding to my case....so to read a txt file and send to arduino, is this necessary to use another software to do it? cant just use arduino code?
Hi Andreas...thanks for your info. I am not using processing before so i just scare will make this become complicated...is it suitable for my case?if yes then i probably will work on this....about gobetwino...i cant find any examples through their blog...so this make me struggling....anyway thanks