# SPI Question

**URL:** <https://forum.arduino.cc/t/spi-question/681286>\
**Category:** Programming\
**Created:** [November 4, 2020, 2:54am UTC](https://forum.arduino.cc/t/spi-question/681286 "2020-11-04T02:54:45Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![krillin22](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@krillin22](https://forum.arduino.cc/u/krillin22)\
**Post date:** [November 4, 2020, 2:54am UTC](https://forum.arduino.cc/t/spi-question/681286/1 "2020-11-04T02:54:45Z")

</div>

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

```arduino
#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.

---

<div class="post-metadata">

**Author:** ![alesam](https://avatars.discourse-cdn.com/v4/letter/a/df788c/32.png) [@alesam](https://forum.arduino.cc/u/alesam)\
**Post date:** [November 4, 2020, 3:00am UTC](https://forum.arduino.cc/t/spi-question/681286/2 "2020-11-04T03:00:32Z")

</div>

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

```cpp
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?

---

<div class="post-metadata">

**Author:** ![krillin22](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@krillin22](https://forum.arduino.cc/u/krillin22)\
**Post date:** [November 4, 2020, 3:04am UTC](https://forum.arduino.cc/t/spi-question/681286/3 "2020-11-04T03:04:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fionning\_macara](https://avatars.discourse-cdn.com/v4/letter/f/43a26b/32.png) [@fionning\_macara](https://forum.arduino.cc/u/fionning_macara)\
**Post date:** [November 4, 2020, 3:12am UTC](https://forum.arduino.cc/t/spi-question/681286/4 "2020-11-04T03:12:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![krillin22](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@krillin22](https://forum.arduino.cc/u/krillin22)\
**Post date:** [November 4, 2020, 3:17am UTC](https://forum.arduino.cc/t/spi-question/681286/5 "2020-11-04T03:17:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alesam](https://avatars.discourse-cdn.com/v4/letter/a/df788c/32.png) [@alesam](https://forum.arduino.cc/u/alesam)\
**Post date:** [November 4, 2020, 4:18am UTC](https://forum.arduino.cc/t/spi-question/681286/6 "2020-11-04T04:18:23Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![fionning\_macara](https://avatars.discourse-cdn.com/v4/letter/f/43a26b/32.png) [@fionning\_macara](https://forum.arduino.cc/u/fionning_macara)\
**Post date:** [November 4, 2020, 4:25am UTC](https://forum.arduino.cc/t/spi-question/681286/7 "2020-11-04T04:25:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![krillin22](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@krillin22](https://forum.arduino.cc/u/krillin22)\
**Post date:** [November 4, 2020, 4:30am UTC](https://forum.arduino.cc/t/spi-question/681286/8 "2020-11-04T04:30:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![CrossRoads](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/crossroads/32/214033_2.png) [@CrossRoads](https://forum.arduino.cc/u/CrossRoads)\
**Post date:** [November 4, 2020, 4:30am UTC](https://forum.arduino.cc/t/spi-question/681286/9 "2020-11-04T04:30:41Z")

</div>

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

> **[Gammon Forum : Electronics : Microprocessors : SPI - Serial Peripheral...](http://www.gammon.com.au/spi)**
>
> Gammon Forum : Electronics : Microprocessors : SPI - Serial Peripheral Interface - for Arduino

---

<div class="post-metadata">

**Author:** ![6v6gt](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/6v6gt/32/225488_2.png) [@6v6gt](https://forum.arduino.cc/u/6v6gt)\
**Post date:** [November 4, 2020, 7:11am UTC](https://forum.arduino.cc/t/spi-question/681286/10 "2020-11-04T07:11:06Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 12:50am UTC](https://forum.arduino.cc/t/spi-question/681286/11 "2021-05-06T00:50:01Z")

</div>


