Issue with SPI and Serial Simultaneously

I am trying to write code that takes a string input from Labview to then change the resistance on a potentiometer using the Arduino Uno. After working with the code, I believe the issue is that the Arduino is not sensing that the string is complete. I wonder if the issue is with SPI and Serial communication at the same time. If anyone has any recommendations, I'd greatly appreciate it.


#include <SPI.h>
#include <string.h>

const int csPin = 9;

String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete

void setup() {


Serial.begin(9600); // initialize serial
inputString.reserve(200); //reserve 200 bytes for the inputString

digitalWrite(csPin, HIGH);


void loop() {

if (stringComplete)
String myString = inputString;
int commaIndex = myString.indexOf(',');
String firstValue = myString.substring(0, commaIndex);
if (firstValue == "1.27"){
// clear the string:
inputString = "";
stringComplete = false;

void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char);
// add it to the inputString:
inputString += inChar;
if (inChar == '\n') {
stringComplete = true;

void digitalPotWrite(int address, int value) {
digitalWrite(csPin, LOW);
byte command = 0xB0;
command += address;
byte byte1 = (value >> 8);
byte byte0 = (value & 0xFF); //0xFF = B11111111
digitalWrite(csPin, HIGH); //de-select slave


Please set code tags around your code!

Describe what issue you have with the code!

You should try to eliminate the use of the String class in your code, it fragments the memory on AVR Arduinos too fast, resulting in non-deterministic behavior of the code.

No, there is nothing stopping you using SPI and Serial at the same time.

Unfortunately, you are using Serial to receive commands from Labview so you have no way to use Serial Monitor to get messages about what your sketch is doing. That leaves you with the built-in LED.

In setup() add:

 digitalWrite(LED_BUILTIN, LOW); // LED off

Then, in place of

    if (inChar == '\n')
      stringComplete = true;


    if (inChar == '\n')
      digitalWrite(LED_BUILTIN, HIGH);
      stringComplete = true;

If the LED turns on you can be sure that the newline character is being recognized.

Move the digitalWrite(LED_BUILTIN, HIGH); to wherever you want to know if that code is being executed.