Getting Redboard + sparkfun Weather Shield readings to Photon [SOLVED]

Hello there

I’m creating an IOT Weather station using Particle Photon and want to use that to display the senosr readings in phone Applications (IOS and Android)

I Have these Products
1- Sparkfun Redboard https://www.sparkfun.com/products/12757
2- Sparkfun Weather Shield https://www.sparkfun.com/products/12081
3- Ofcourse Particle Photon https://www.sparkfun.com/products/13774?_ga=1.255334721.895638929.1472993655

Now I’m getting the readings i want using the Arduino IDE from the sensors but the thing that i have no clue about is getting those readings to the photon

as stated before i want to display the weather shield sensor readings in IOS and Android Apps so my main idea is using the Particle Android and IOS SDKS

another thing I’m Looking into is BLYNK http://www.blynk.cc/ which is an app that connects to your board and can display sensor readings

is there a way i can get my sparkfun weather shield sensor readings to the photon and use BLYNK to display them (that would save much of my time developing
two apps on two different platforms using the SDKS ) ??

You mention you’re able to read the values using the Arduino IDE. What board are you using for that?

Just to clarify, you’re not getting the sensor data to the photon, but you’re using the photon to operate the sensor, thus getting data. Depending on which sensors you’d like to use, several libraries are available to make that process easier. The Redboard is using the P1 module, but should functionally be the same as a Photon.

As for Blynk, if you do a search on the community, you’ll find various topics covering this. Have a look :slight_smile:

@Moors7, he’s using the Arduino RedBoard and unfortunately (;-)) not the Photon ReadBoard
I’d actually also switch to the all-in-one solution or the dedicated Photon Weather Shield rather than transfering the data from one MCU to another.

But it’s doable multiple ways. The probably easiest one is via RX/TX USART.

1 Like

My Hardware is Sparkfun Redboard with sparkfun weather shield attached to it
Similar to this :smile:

I See your point … i was on a tight schedule to complete the project and hadn’t search enough of how I’m gonna implement this , i was going to make a second order of the photon redboard but the shipment takes two weeks and i cant afford that

So I’m Trying to make do of what i have right now

“But it’s doable multiple ways. The probably easiest one is via RX/TX USART”

Music to my ears :smile:

if you have any tips , Links , Toturials of how to transfer data from arduino redboard to the photon using this method that would be much helpful

Thank you …

There are several threads in this forum that could get you started
https://community.particle.io/search?q=arduino%20photon

Most of them get stuck at some point, that’s why the posted here, but the solutions should be there too.

But if this doesn’t get you anywhere, we’re here to help :wink:

This seems to be a good one, although the level shifting should not be required for the Photon as the RX/TX pins are 5V tolerant.

There are also some things that have slightly changed since 2014, but the general idea is in the code.

Okay , after searching for a few days for UART serial communication i found this github Link

i tried the example and it worked great.

the thing im trying to figure out now is how to transfer a structure of data from the arduino to the photon

I Have this Structure

struct package
{
   int temperature;
   int humidity;
  long int pressure;
   int luminosity;
   int winddir;
   int windspeed;
   int rainfall;
};

typedef struct package Package;
Package data;

I’m receiving these readings from another station located outdoor by 433 MHZ wireless transmission modules

now in arduino in the void loop method i can set those readings each time they are received to an array like

long int readings [] = {data.temperature , data.humidity , data.pressure , data.luminosity , data.winddir , data.windspeed , data.rainfall };

what i need is to have this array with the values associated to it in each loop in the arduino at the photon side…

is it possible ??

just for the sake of it i found how to set values from the particle web ide to the BLYNK app using this link

http://docs.blynk.cc/#blynk-main-operations-get-data-from-hardware-pushing-data-from-hardware

so the missing link of my project now is getting those readings from the arduino array to the photon

You can send binary data via Serial1.write() but the problem with sending int between the to is the difference in endianness and size of datatypes.
On Photon both, int and long int, are 32bit while on Arduino int is 16bit.
So you might use the more explicit int16_t and int32_ on the Photon and you need to invert the byte order small endian (Arduino) to big endian (Photon).

Here’s an example, similar to the one in my serial tutorial, for sending multiple values from the Arduino to the Photon. It uses snprintf on the Arduino side to print the numbers as text and sscanf on the Photon side to reverse the process.

Arduino code

// Arduino code

// Constants

// Structures
typedef struct {
  int temperature;
  int humidity;
  int pressure;
  int luminosity;
  int winddir;
  int windspeed;
  int rainfall;
} WeatherData;

// Forward declarations
void getWeatherData(WeatherData &data);
void sendWeatherData(const WeatherData &data);

// Global variables
char sendBuf[256];

void setup() {
  // Serial TX (1) is connected to Photon RX
  // Serial RX (0) is connected to Photon TX
  // Ardiuno GND is connected to Photon GND
  Serial.begin(19200);
}

void loop() {
  WeatherData data;
  getWeatherData(data);
  sendWeatherData(data);
  delay(5000);
}

void getWeatherData(WeatherData &data) {
  // This just generates random data for testing
  data.temperature = rand();
  data.humidity = rand();
  data.pressure = rand();
  data.luminosity = rand();
  data.winddir = rand();
  data.windspeed = rand();
  data.rainfall = rand();
}

void sendWeatherData(const WeatherData &data) {

  snprintf(sendBuf, sizeof(sendBuf), "%d,%d,%d,%d,%d,%d,%d\n",
      data.temperature, data.humidity, data.pressure, data.luminosity, data.winddir, data.windspeed, data.rainfall);
  Serial.print(sendBuf);
}

Photon code

#include "Particle.h"

// Constants
const size_t READ_BUF_SIZE = 256;

// Structures
typedef struct {
	int temperature;
	int humidity;
	int pressure;
	int luminosity;
	int winddir;
	int windspeed;
	int rainfall;
} WeatherData;

// Forward declarations
void processBuffer();
void handleWeatherData(const WeatherData &data);

// Global variables
int counter = 0;
unsigned long lastSend = 0;

char readBuf[READ_BUF_SIZE];
size_t readBufOffset = 0;

void setup() {
	Serial.begin(9600);

	// Serial1 RX is connected to Arduino TX (1)
	// Serial2 TX is connected to Arduino RX (0)
	// Photon GND is connected to Arduino GND
	Serial1.begin(19200);
}

void loop() {

	// Read data from serial
	while(Serial1.available()) {
		if (readBufOffset < READ_BUF_SIZE) {
			char c = Serial1.read();
			if (c != '\n') {
				// Add character to buffer
				readBuf[readBufOffset++] = c;
			}
			else {
				// End of line character found, process line
				readBuf[readBufOffset] = 0;
				processBuffer();
				readBufOffset = 0;
			}
		}
		else {
			Serial.println("readBuf overflow, emptying buffer");
			readBufOffset = 0;
		}
	}

}

void processBuffer() {
	// Serial.printlnf("Received from Arduino: %s", readBuf);
	WeatherData data;

	if (sscanf(readBuf, "%d,%d,%d,%d,%d,%d,%d", &data.temperature, &data.humidity, &data.pressure,
			&data.luminosity, &data.winddir, &data.windspeed, &data.rainfall) == 7) {

		handleWeatherData(data);
	}
	else {
		Serial.printlnf("invalid data %s", readBuf);
	}
}

void handleWeatherData(const WeatherData &data) {
	Serial.printlnf("got temperature=%d humidity=%d pressure=%d luminosity=%d winddir=%d windspeed=%d rainfall=%d",
			data.temperature, data.humidity, data.pressure, data.luminosity, data.winddir, data.windspeed, data.rainfall);
}

2 Likes

Apologies for not replying earlier … :sweat:

@ScruffR Thanks, i will keep that in mind :relieved:

@rickkas7 Thank you so much bro your code worked like charm, :heart_eyes: :heart_eyes: i was able to to get those reading to my photon
and the only thing i added is pushing those readings each loop to the BLYNK app using:

Blynk.virtualWrite(V3, data.temperature) 

Result :

Thank you again …

1 Like