I'm trying to run my code but I keep getting this error
in function 'void loop()';
33:27: error: invalid conversion from 'char*' to 'int' [-fpermissive]
7:0:
111:8: note: initializing argument 1 of 'void Servo::write(int)'
exit status 1
I am supposed create an SPI circuit using Servo with 2 arduino boards.
Here is my code
#include <SPI.h>
char buff [50];
volatile byte indx;
volatile boolean process;
#include <Servo.h> // This library allow to communicate with servo
Servo servo1; //assigning the name to the servo
void setup (void) {
Serial.begin (115200);
pinMode(MISO, OUTPUT); // have to send on master in so it set as output
SPCR |= _BV(SPE); // turn on SPI in slave mode
indx = 0; // buffer empty
process = false;
SPI.attachInterrupt(); // turn on interrupt
servo1.attach(2); // Configure pin 2 to servo
}
ISR (SPI_STC_vect) // SPI interrupt routine
{
byte c = SPDR; // read byte from SPI Data Register
if (indx < sizeof buff) {
buff [indx++] = c; // save data in the next index in the array buff
if (c == '\r') //check
process = true;
}
}
void loop (void) {
if (process) {
process = false; //reset the process
Serial.println (buff); //print the array on serial monitor
servo1.write( buff );//move the servo to desired angle
indx= 0; //reset button to zero
}
}
krillin22:
I am supposed create an SPI circuit using Servo with 2 arduino boards.
Can you elaborate on that? Does that mean you have a servo on one board A and the other board B has to control the servo by sending the position from B to A over spi? Or what?
Yes this is what it's supposed to do. It takes the photoresistor information which is on the master and sends it to the slave which is the servo over SPI
I'm surprised that as someone "new to this" you're dabbling in using an Arduino as an spi slave which is beyond the functionality of the standard library and requires you to operate deep down in the guts of spi's registers and so on.
Your problem is probably not the spi slave, (I guess you have found some working code), it is interpreting the contents of that buffer which has been sent from the other device (spi master) and using the data to control the servos.
What is in that buffer and in what format?
What are the servos supposed to do and under what circumstances?