SPI Question

Hello,

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
   }
}

Any help would be greatly appreciated.

It's related to SPI. You are trying to pass an array to servo write method:

servo1.write( buff );//move the servo to desired angle

While it accept an integer. What are you trying to achieve sending array instead of single number to servo?

So what do I change it to? Sorry, I'm new to this

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

krillin22:
So what do I change it to? Sorry, I'm new to this

I don't know. It depends on your design.

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.

Yes, I am new to this. I've only been using Arduino for about 2 months right now and it is part of an assignment that I am stuck on

See "How to make an SPI slave", about 1/4 of the way down the page

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?