Hi There !
Thanks for your reply !
What I want is controlling servo`s and motors via Uno or Mega.
I have downloaded and installed everything in this : Principialabs.com : setup, and it is working on USB.
What I now want to, is to do the exact same thing, via ethernet…
I need to “forward” my COM port to ethernet, AND make my Uno/Mega to talk via ethernet…and ethernet board…
When this is up and running, there will be MANY things to do with this !
When this is working I will try (my self) to add gyro, temp, light, etc…etc… sensors, but as mentioned, my big problem now is to get the ethernet implemented in the sketch…
What I have tried to implement is the UDP send/recieve string, as I believe that this would be the best suitable…please correct me if I am wrong
(need to send and receive info from the board)
Here is the code that is on the Uno today (I realize now, that the Python is on my laptop…
:
/*
*/
// Import the Arduino Servo library
#include <Servo.h>
// Create a Servo object for each servo
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
// TO ADD SERVOS:
// Servo servo5;
// etc…
// Common servo setup values
int minPulse = 600; // minimum servo position, us (microseconds)
int maxPulse = 2400; // maximum servo position, us
// User input for servo and position
int userInput[3]; // raw input from serial buffer, 3 bytes
int startbyte; // start byte, begin reading input
int servo; // which servo to pulse?
int pos; // servo angle 0-180
int i; // iterator
// LED on Pin 13 for digital on/off demo
int ledPin = 13;
int pinState = LOW;
void setup()
{
// Attach each Servo object to a digital pin
servo1.attach(2, minPulse, maxPulse);
servo2.attach(3, minPulse, maxPulse);
servo3.attach(4, minPulse, maxPulse);
servo4.attach(5, minPulse, maxPulse);
// TO ADD SERVOS:
// servo5.attach(YOUR_PIN, minPulse, maxPulse);
// etc…
// LED on Pin 13 for digital on/off demo
pinMode(ledPin, OUTPUT);
// Open the serial connection, 9600 baud
Serial.begin(9600);
}
void loop()
{
// Wait for serial input (min 3 bytes in buffer)
if (Serial.available() > 2) {
// Read the first byte
startbyte = Serial.read();
// If it’s really the startbyte (255) …
if (startbyte == 255) {
// … then get the next two bytes
for (i=0;i<2;i++) {
userInput = Serial.read();
- }*
- // First byte = servo to move?*
- servo = userInput[0];*
- // Second byte = which position?*
- pos = userInput[1];*
- // Packet error checking and recovery*
- if (pos == 255) { servo = 255; }*
- // Assign new position to appropriate servo*
- switch (servo) {*
- case 1:*
- servo1.write(pos); // move servo1 to ‘pos’*
- break;*
- case 2:*
- servo2.write(pos);*
- break;*
- case 3:*
- servo3.write(pos);*
- break;*
- case 4:*
- servo4.write(pos);*
- break;*
- // TO ADD SERVOS:*
- // case 5:*
- // servo5.write(pos);*
- // break;*
- // etc…*
- // LED on Pin 13 for digital on/off demo*
- case 99:*
- if (pos == 180) {*
- if (pinState == LOW) { pinState = HIGH; }*
- else { pinState = LOW; }*
- }*
- if (pos == 0) {*
- pinState = LOW;*
- }*
- digitalWrite(ledPin, pinState);*
- break;*
- }*
- }*
- }*
}
[/table]
I am really looking forward to your reply ! ! $)