Skip to main content
added 5 characters in body
Source Link
ZanQdo
  • 31
  • 1
  • 1
  • 5

I guess I'll answer my own question for anyone else having this issue. What I did was:

Python:

# write to arduino as raw binary
bge.arduino.write(struct.pack('>BBB',45,90,180))

Arduino:

#include <Servo.h>

Servo servo0;
Servo servo1;
Servo servo2;

// create array
int incoming[2];

void setup(){
  Serial.begin(9600);
  
  servo0.attach(3);
  servo1.attach(5);
  servo2.attach(6);
}

void loop(){
  while(Serial.available() >= 3){
    // fill array
    for (int i = 0; i < 3; i++){
      incoming[i] = Serial.read();
    }
    // use the values
    servo0.write(incoming[0]);
    servo1.write(incoming[1]);
    servo2.write(incoming[2]);
  }
}

I guess I'll answer my own question for anyone else having this issue. What I did was:

Python:

# write to arduino as raw binary
bge.arduino.write(struct.pack('>BBB',45,90,180))

Arduino:

#include <Servo.h>

Servo servo0;
Servo servo1;
Servo servo2;

// create array
int incoming[2];

void setup(){
  Serial.begin(9600);
  
  servo0.attach(3);
  servo1.attach(5);
  servo2.attach(6);
}

void loop(){
  while(Serial.available()){
    // fill array
    for (int i = 0; i < 3; i++){
      incoming[i] = Serial.read();
    }
    // use the values
    servo0.write(incoming[0]);
    servo1.write(incoming[1]);
    servo2.write(incoming[2]);
  }
}

I guess I'll answer my own question for anyone else having this issue. What I did was:

Python:

# write to arduino as raw binary
bge.arduino.write(struct.pack('>BBB',45,90,180))

Arduino:

#include <Servo.h>

Servo servo0;
Servo servo1;
Servo servo2;

// create array
int incoming[2];

void setup(){
  Serial.begin(9600);
  
  servo0.attach(3);
  servo1.attach(5);
  servo2.attach(6);
}

void loop(){
  while(Serial.available() >= 3){
    // fill array
    for (int i = 0; i < 3; i++){
      incoming[i] = Serial.read();
    }
    // use the values
    servo0.write(incoming[0]);
    servo1.write(incoming[1]);
    servo2.write(incoming[2]);
  }
}
deleted 111 characters in body
Source Link
ZanQdo
  • 31
  • 1
  • 1
  • 5

I guess I'll answer my own question for anyone else having this issue. What I did was:

Python:

# write to arduino as raw binary
bge.arduino.write(struct.pack('>BBB',45,90,180))

Arduino:

#include <Servo.h>

Servo servo0;
Servo servo1;
Servo servo2;

// create array
int incoming[2];

void setup(){
  Serial.begin(9600);
  
  servo0.attach(3);
  servo1.attach(5);
  servo2.attach(6);
}

void loop(){
  ifwhile(Serial.available()){
    // fill array
    for (int i = 0; i < 3; i++){
      incoming[i] = Serial.read();
    }
    // use the values
    servo0.write(incoming[0]);
    servo1.write(incoming[1]);
    servo2.write(incoming[2]);
  }
}

Now there seems to be an issue with the array sometimes being filled in different order or something.. oh boy.

I guess I'll answer my own question for anyone else having this issue. What I did was:

Python:

# write to arduino as raw binary
bge.arduino.write(struct.pack('>BBB',45,90,180))

Arduino:

#include <Servo.h>

Servo servo0;
Servo servo1;
Servo servo2;

// create array
int incoming[2];

void setup(){
  Serial.begin(9600);
  
  servo0.attach(3);
  servo1.attach(5);
  servo2.attach(6);
}

void loop(){
  if(Serial.available()){
    // fill array
    for (int i = 0; i < 3; i++){
      incoming[i] = Serial.read();
    }
    // use the values
    servo0.write(incoming[0]);
    servo1.write(incoming[1]);
    servo2.write(incoming[2]);
  }
}

Now there seems to be an issue with the array sometimes being filled in different order or something.. oh boy.

I guess I'll answer my own question for anyone else having this issue. What I did was:

Python:

# write to arduino as raw binary
bge.arduino.write(struct.pack('>BBB',45,90,180))

Arduino:

#include <Servo.h>

Servo servo0;
Servo servo1;
Servo servo2;

// create array
int incoming[2];

void setup(){
  Serial.begin(9600);
  
  servo0.attach(3);
  servo1.attach(5);
  servo2.attach(6);
}

void loop(){
  while(Serial.available()){
    // fill array
    for (int i = 0; i < 3; i++){
      incoming[i] = Serial.read();
    }
    // use the values
    servo0.write(incoming[0]);
    servo1.write(incoming[1]);
    servo2.write(incoming[2]);
  }
}
edited body
Source Link
ZanQdo
  • 31
  • 1
  • 1
  • 5

I guess I'll answer my own question for anyone else having this issue. What I did was:

Python:

# write to arduino as raw binary
bge.arduino.write(struct.pack('>BBB',45,90,180))

Arduino:

#include <Servo.h>

Servo servo0;
Servo servo1;
Servo servo2;

// create array
int incoming[2];

void setup(){
  Serial.begin(9600);
  
  servo0.attach(3);
  servo1.attach(5);
  servo2.attach(6);
}

void loop(){
  if(Serial.available()){
    // fill array
    for (int i = 0; i < 6;3; i++){
      incoming[i] = Serial.read();
    }
    // use the values
    servo0.write(incoming[0]);
    servo1.write(incoming[1]);
    servo2.write(incoming[2]);
  }
}

Now there seems to be an issue with the array sometimes being filled in different order or something.. oh boy.

I guess I'll answer my own question for anyone else having this issue. What I did was:

Python:

# write to arduino as raw binary
bge.arduino.write(struct.pack('>BBB',45,90,180))

Arduino:

#include <Servo.h>

Servo servo0;
Servo servo1;
Servo servo2;

// create array
int incoming[2];

void setup(){
  Serial.begin(9600);
  
  servo0.attach(3);
  servo1.attach(5);
  servo2.attach(6);
}

void loop(){
  if(Serial.available()){
    // fill array
    for (int i = 0; i < 6; i++){
      incoming[i] = Serial.read();
    }
    // use the values
    servo0.write(incoming[0]);
    servo1.write(incoming[1]);
    servo2.write(incoming[2]);
  }
}

Now there seems to be an issue with the array sometimes being filled in different order or something.. oh boy.

I guess I'll answer my own question for anyone else having this issue. What I did was:

Python:

# write to arduino as raw binary
bge.arduino.write(struct.pack('>BBB',45,90,180))

Arduino:

#include <Servo.h>

Servo servo0;
Servo servo1;
Servo servo2;

// create array
int incoming[2];

void setup(){
  Serial.begin(9600);
  
  servo0.attach(3);
  servo1.attach(5);
  servo2.attach(6);
}

void loop(){
  if(Serial.available()){
    // fill array
    for (int i = 0; i < 3; i++){
      incoming[i] = Serial.read();
    }
    // use the values
    servo0.write(incoming[0]);
    servo1.write(incoming[1]);
    servo2.write(incoming[2]);
  }
}

Now there seems to be an issue with the array sometimes being filled in different order or something.. oh boy.

Source Link
ZanQdo
  • 31
  • 1
  • 1
  • 5
Loading