I followed this tutorial here in hopes of establishing serial communication between an Arduino Uno and Spark Core. The only difference is that I’m not using a logic level converter but a 10 k resistor. Here is my current setup:
Running this the only output I receive in the sketch window is SERIAL: BEGIN.
Searching around it seems that using a 10k resister should work fine but this is the only place I could possible see this breaking. Any help is very much appreciated!
You setup the Software Serial on the Arduino's Hardware Serial pins... what's your intention here? To use Arduino Hardware Serial to receive characters, that get forwarded to a software serial output, which is hooked to Spark Serial1, which is then forwarded to Spark Serial over USB?
If so, define Software serial on D2, D3 and connect those to Serial1 of the Spark and try again
A 10k series, and 20k pull down will divide your 5V to 3.33V. So add a 20k (10k and 10k in series) pull down resistor to your Serial1 RX input to be fully legit with your voltage levels
4.7k series and 10k pull down is also good, if you have those.
I am going to apologize on the front end for my amateurness and thank you for the help. Basically what I’m trying to do is send a char from the Arduino to the Spark. That link to the tutorial in my OP was the only one I could find that sent data from an Arduino to a Spark.
My goal is to be able to send a char from the Arduino to the Spark.
Turn the char into a string
Use Spark.publish to push that string to a server and store it in a database.
I have been able to get 2 and 3 working fine. It’s just getting the data from my Arduino to the Spark that’s driving me crazy .
This doesn’t really make sense to me but in the code posted above the pin settings are reversed in the Arduino code, this is the only way I can produce output. If I set them up correct with RX, TX pins correctly declared I get no output (red and white wires reversed in photo above).
Basically you don’t even need to hook up the red wire as pictured above… if you are not doing any bi-directional communication (i.e. all communication is from Arduino to Spark).
You will need to swap your white and black wires in the mini breadboard though. The way you have it is 10k series and 5k pulldown, but should be the other way around.
Also SoftwareSerial ser(2, 3); // RX, TX so D3 would be the TX from the Arduino (so swap your Red/Wire wires from the picture above … just just ditch the Red wire and move White to D3).
Fingers crossed this time!
BTW: Thanks for the clear pictures! That really helps to debug.
And here is the Spark code I’m using to take in a char and do the publish() function.
char publishString[40];
void setup() {
//This works correctly and I am able to see it server side
sprintf(publishString,"%s", "setup() began.");
Spark.publish("Uptime",publishString);
Serial.begin(9600);
}
void loop() {
while (Serial.available() > 0)
{
sprintf(publishString,"%s", "We have incoming data");
Spark.publish("Uptime",publishString);
}
}
The first time I call Spark.publish it works and I am able to see on the server so I know that part is working. I’m still seeing no output from serial communication. Could it be because I’m outputting too much from the Arduino? That sounds weird but I guess it could be possible.
As disclosure I am a long time objective-c developer but my hardware knowledge is lacking. Spark got me excited about learning it so thank you for holding my hand.
I don’t see a ground wire between the Arduino and Spark boards–are they powered off the same power supply? If not, you need one more wire, a ground-to-ground connection.
I’m afraid that I am still never entering the Serial1.available() > 0while statement. Is sending this data through serial the correct approach?
If I’m doing a SoftwareSerial out of the Arduino, is going into the RX pin on the Spark the correct method (I thought RX was hardware serial?)?
Would a better method be to go from one of the digital pins on the Arduino to one of the digital pins on the Spark? From the docs I see that the D pins can handle 5v in. That way there would be no need for any step downs.
Does that make sense or am I way out in left field
Also, here is my updated Spark code:
char publishString[40];
void setup() {
delay(1000);
//This works correctly and I am able to see it server side
sprintf(publishString,"%s", "setup() began.");
Spark.publish("Uptime",publishString);
Serial1.begin(9600);
}
void loop() {
while (Serial1.available() > 0)
{
sprintf(publishString,"%s", "We have incoming data");
Spark.publish("Uptime",publishString);
}
}
Yes, the RX pin on the Spark core is correct. You are using SoftwareSerial on the Arduino, but software serial does not currently work on Spark (there are three hardware serial ports, USB and two on the core pins instead). You have the ground wire there too, right?
You are eventually going to run into the Spark.publish() rate limit of an average of one per second with a burst of four allowed, since when it works you will publishing way too many events. You could add a delay(1000); after the ser.write(‘h’); on the Arduino side to slow it down.
I am still suspicious of your voltage divider–a real level-shifter would be a lot better.
You could try the hardware serial on the Arduino I guess–the TX pin is open right there in your photo.
char publishString[40];
void setup() {
delay(1000);
//This works correctly and I am able to see it server side
sprintf(publishString,"%s", "setup() began.");
Spark.publish("Uptime",publishString);
//Fire up Serial1
Serial1.begin(9600);
}
void loop() {
while (Serial1.available() > 0)
{
//Print out up to server that we have had data come in
sprintf(publishString,"%s", "We have incoming data");
Spark.publish("Uptime",publishString);
}
}
HTML code to display in webpage when data has been received:
Hah! Of all the things I picked up on I didn't see that one Good catch @bko
I was doing very similar things last night with my Arduino, level shifting down to 3.3V with resistors to simulate the Spark Core, then back up to 5V using a fast buffer like the SN74HCT125N to drive a different variant of the NeoPixel strip. It was working great, but I did in fact think about the grounds at that point
Sometimes these problems are as much about what's missing as what's wired wrong or coded in error.
First thank you so much for posting this, it is very helpful and I appreciate the efforts to post the working prototype after the success!
Yet I have some problems to make it work, and I can’t understand why… Help will be very much appreciated.
Several questions:
The wire is connected to the TX port in the Arduino kit, correct?
Which resistors did you use? 330Ohm or 10KOhm?
In the Photon you connected the the wires to GND and RX, correct?
I am attaching 2 files: one of them is the only thing I can see after my HTTP request, and the other are my wiring. I will be more than glad if anyone will let me know what is wrong here???
Unlike to its predecessor the Core on the Photon RX and TX are 5V tolerant, so you won’t need any resistors between the Arduino and Photon (providing you only ever use these pins via Serial1 and don’t set your own pinMode() for them).
The wiring should be
Arduino Photon
GND GND
TX RX
RX TX // for good measure to talk back
--- if you don't use the USB connection for data ---
--- you could power the Photon off Arduino too ---
+5V Vin
I’ve duplicated the working code and wiring above, and can see the output a few times in Dashboard. However, after roughly 60 seconds, the Photon begins breathing green. I’ve tried various baud rates, delays, etc. and it still results in a breathing green Photon after ~60 seconds. I also tried disconnecting the RX line (no incoming data) and always end up with the breathing green Photon.
What code exactly are you running?
For instance the code above contains a Spark.publish() instruction that will violate the rate limit for publishes and hence will throw off the connection after a while.
Thanks for the reply ScruffR, I think you may have answered my question but I’m going to post the code as you asked - just so I’m 100% sure.
I copied/pasted the following code directly into build - which is what results in the breathing green.
char publishString[40];
void setup() {
delay(1000);
//This works correctly and I am able to see it server side
sprintf(publishString,"%s", "setup() began.");
Spark.publish("Uptime",publishString);
//Fire up Serial1
Serial1.begin(9600);
}
void loop() {
while (Serial1.available() > 0)
{
//Print out up to server that we have had data come in
sprintf(publishString,"%s", "We have incoming data");
Spark.publish("Uptime",publishString); // IS THIS MY PROBLEM?
}
}
If I’m understanding you correctly, the loop() repeats so fast that it violates the rate limit, and therefore causes me problems. Would the solution then be to put in a delay(10000); or something?
Ultimately, I’m trying to send GPS data from an Arduino UNO to the Photon. I don’t need that GPS data updated in real-time (I only need it when I need it), so maybe the more sensible solution would be to publish() only when I ask for it? If that’s the case, what should I Google for?
Again, thanks so much for the helpful response. Not looking to be spoon-fed here, but my problem is that I just don’t know what I should ask for - hence the part about “what should I Google for”.
A delay(1010) (due to a “bug” 1000 is not quite enough) should do.
And to only publish on when you get data sent via Serial1 you’d need to empty the RX buffer each time you fall into your while().
As you don’t do any Serial1.read() in there the buffer will always have bytes available and hence you are never coming back out of that while() and this is your main issue.
But why exactly do you need the GPS data off the Arduino and don’t just let the Photon read the GPS module direct?