Control i-sobot arm, serial comunication

hello, I am making a program to control the arm of an i-sobot robot, the arm has three motors, I use three potentiometers to indicate the angle, the communication that the robot uses is a protocol that consists of a start byte, 5 bytes of angle, one of checksum and one of closure, in the case of the arm only 3 bytes of angle are used and the rest are left with a value of 128, I made the program and I can control the position of 2 joints, any of the three , but only 2, the problem is when I try to add the third potentiometer the robot freezes and does not move, I don't know if it is because of how to send the data to the robot, or it is another problem. Thank you if you have any answers and sorry for my bad english.

#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3

SoftwareSerial mySerial(rxPin, txPin);

int J[5];
int cks = 0;
void joints();
byte data[8];

void setup()
{
  Serial.begin(9600);
  mySerial.begin(2400);
  
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
}

void loop()
{
  
  J[0] = 128 + map(analogRead(A0), 0, 1023, -128, 92);
  J[1] = 128 + map(analogRead(A1), 0, 1023, -128, 92);
  J[2] = 128 + map(analogRead(A2), 0, 1023, -128, 92);

joints(J[0], J[1], J[2], 128, 128, 0, 0);
}

void joints(int D1, int D2, int D3, int D4, int D5, int s0, int s1) {
  
  if (s0 == 0 && s1 == 0) {D4 = 128; D5 = 128;}
  if (s0 == 0 && s1 == 1) {D5 = 128;}

  cks = (260 + D1 + D2 + D3 + D4 + D5) % 255;
  data[0]=5;
  data[1]=D1;
  data[2]=D2;
  data[3]=D3;
  data[4]=D4;
  data[5]=D5;
  data[6]=cks;
  data[7]=255;
  
  mySerial.write(data,8);

}

Post the complete you did it it worked 2 pot moving 2 joints sketch please.

a7

If you add the third potentiometer to only send data to the Serial Monitor, without connecting the output to the robot, do you see any robot movement and Serial Monitor data?

the solution is the secuence of data, the first bye is 255

My solution!

And by the way, this topic is repost even if you wrote it in English

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.