wire write values
i want have joystick connected arduino-controller, , motor connected arduino-robot.
i first trying test serial communication between 2 arduinos down serial wire. (i not plan run final project way, intend try wireless connection,, i've ordered cheap 4333mhz transmitters)
i have joystick working me when in 1 arduino. podged codes how had them,, paste codes (not working or tried), can see hoped result joystick. , down mapped motor outputs on 2 pins, connected little h-bridge breadboarded out of regular to-92 4401 transistors. motor tiny @ present, works. using joystick can go forward , backward on single motor while working code on single arduino.
i've split code slave-master , did manage communication between 2 devices,, no matter did on joystick recieved full forward power, , in serial monitor printed 255 only. ,, think did not encode motorinstruct down wire, , wire.read merely reading kind of string input or something, , being mapped 255 incidentally.
i first trying test serial communication between 2 arduinos down serial wire. (i not plan run final project way, intend try wireless connection,, i've ordered cheap 4333mhz transmitters)
i have joystick working me when in 1 arduino. podged codes how had them,, paste codes (not working or tried), can see hoped result joystick. , down mapped motor outputs on 2 pins, connected little h-bridge breadboarded out of regular to-92 4401 transistors. motor tiny @ present, works. using joystick can go forward , backward on single motor while working code on single arduino.
i've split code slave-master , did manage communication between 2 devices,, no matter did on joystick recieved full forward power, , in serial monitor printed 255 only. ,, think did not encode motorinstruct down wire, , wire.read merely reading kind of string input or something, , being mapped 255 incidentally.
code: [select]
#include <wire.h>
int joypin = a0;
void setup() {
// put setup code here, run once:
wire.begin(); // join i2c bus (address optional master)
pinmode(joypin, input);
}
void loop() {
// put main code here, run repeatedly:
int motorinstruct = analogread(a0);
wire.begintransmission(8); // transmit device #8
wire.write(motorinstruct); // sends 5 bytes
wire.endtransmission(); // stop transmitting
delay (50);
}
code: [select]
#include <wire.h>
int motorpinf = 3;
int motorpinb = 5;
void setup() {
// put setup code here, run once:
wire.begin(8); // join i2c bus address #8
serial.begin(9600); // start serial output
pinmode(motorpinf, output);
pinmode(motorpinb, output);
}
void loop() {
// put main code here, run repeatedly:
int motorinstruct = wire.read();
motorinstruct = map (motorinstruct, 0, 1023, -255, 255);
serial.print(motorinstruct);
if (motorinstruct >= -255 && motorinstruct <= -51)
{
analogwrite(motorpinb, -motorinstruct);
analogwrite(motorpinf, 0);
}
if (motorinstruct >= 51 && motorinstruct <=255)
{
analogwrite(motorpinf, motorinstruct);
analogwrite(motorpinb, 0);
}
if (motorinstruct >= -50 && motorinstruct <= 50)
{
analogwrite(motorpinf, 0);
analogwrite(motorpinb, 0);
}
serial.print(motorinstruct); // print character
delay(50);
}
Arduino Forum > Using Arduino > Programming Questions > wire write values
arduino
Comments
Post a Comment