Arduino to Spark Communication

Hello @Ricky here. For the last few days I have been working on establishing Serial Communication between the Spark Core and Arduino. I have them connected and I have the code, no blown up boards yet! Just there is one small problem, I am receiving things from the Arduino that I didn’t send in the first place. For example I am sending x from the Arduino, but on the Spark Core serial monitor I am receiving 255! I did a bit of research and I thing that this is the Ascii Characters, something that I have come across in other projects that I have done. I am posting this to see if anyone has ever come across it and knows what to do. If you need it here is my code:

Arduino code:

 #include <Wire.h> // include wire library

void setup()
{
  Wire.begin();
  Serial.begin (9600);
  // join i2c bus (address optional for master)
}

byte x = 0;

void loop()
{
  Wire.beginTransmission(4); // transmit to device #4 (Spark Core)
  Serial.print ("Sending in 1 second");
  Serial.println();
  delay (1000);
  Wire.write("x is ");
  Wire.write(x);  
  Serial.print ("Sent"); // Serial monitoring to see where the program is at
  Serial.println();
  delay (3000);
  Wire.endTransmission();    // stop transmitting

  x++; // add to x
  delay(1000);
}

Spark Core code:

void setup() {
    Serial.begin (9600);
    Serial1.begin (9600); // used for communication to other devices
}

void loop() { 
    if (Serial1.available ()) {
        Serial.print (Serial1.read ());
    }
}

If you need it here is my wiring:

Thanks @Ricky

I’d suggest plugging in the power, that might help :stuck_out_tongue: Also, could you perhaps say which connections you’ve used, since it’s pretty hard to see in the picture?

I have A4 on Arduino hooked up to RX on Spark. I also have Gnd between the two.

You’re using the Wire.h library in the arduino - that’s for I2C devices - not serial. If you want to read via the TX/RX pin on the Core you’ll need to use Serial1 on the arduino to send the data, and change the A4 connection to the TX pin.

I forgot to mention, that I have the Arduino UNO R3, which has a switch that gives off different power, 3.3v or 5v.

Thank you @mdma, do you know how to do the structure of the Arduino code?

It’s just like Serial (which goes to USB) but you use Serial1 instead (which goes to the TX/RX pins).

You add Serial1.begin(9600) to the setup() function and use Serial1.write() in the loop to write the data to the TX pin.

Btw, on the spark code there’s a mistake - using print rather than write, it should instead read

Serial.write(Serial1.read());

"

Thank you @mdma

When I try to verify the program it comes up with:

Serial1 was not declared in this scope

Here is the program I have right now:

int communicate = 1;

void setup()
{
  Serial1.begin (9600);
}

void loop()
{
  if (Serial1.available ())
  {
    Serial1.write (communicate);
  }
}

If you get the not declared message you are likely to be missing an #include "application.h".