I hope this is the correct forum...
Setup: raspberry Pi B+ with an Alamode board on top as the Arduino. Connected to the alamode are 4, swiss flow SF-80 flow meters and an ID-12 RFID reader.
If I run a basic bit of arduino code:
#include <SoftwareSerial.h>
// The RFID module's TX pin needs to be connected to the Arduino.
#define rxPin 7
#define txPin 6
// Create a software serial object for the connection to the RFID module
SoftwareSerial rfid = SoftwareSerial( rxPin, txPin );
void setup() {
Serial.begin(9600); // Serial port for connection to host
rfid.begin(9600); // Serial port for connection to RFID module
}
char reads;
void loop() {
while(rfid.available()>0)
{
reads = rfid.read();
Serial.print(reads);
}
}
it displays the rfid tag value correctly and I can read it via a python script on the raspberry pi.
When I run my code to read and out put in the information from the flow meters, that portion works.
So I know both the flow meters and the RFID reader are working with the raspPi/Alamode setup.
What I am trying to do is enable it so that when a person swipes their tag in front of the reader and then pours from a tap, the RFID Tag Value, the Pin Number and the Pulse Count from the flow meters are passed to the python script.
This is what I have:
#include <SoftwareSerial.h>
// The RFID module's TX pin needs to be connected to the Arduino.
#define rxPin 7
#define txPin 6
// Create a software serial object for the connection to the RFID module
SoftwareSerial rfid = SoftwareSerial( rxPin, txPin );
//#include <SPI.h> // SPI is used to control the OpenSegment Shield
//This line is the number of flow sensors connected.
const uint8_t numSensors = 4;
//This line initializes an array with the pins connected to the flow sensors
uint8_t pulsePin[] = {8,9,10,11};
//number of milliseconds to wait after pour before sending message
unsigned int pourMsgDelay = 300;
unsigned int pulseCount[numSensors];
unsigned int kickedCount[numSensors];
unsigned long nowTime;
unsigned long lastPourTime = 0;
unsigned long lastPinStateChangeTime[numSensors];
int lastPinState[numSensors];
char tagValue[10];
unsigned long lastSend = 0;
void setup() {
pinMode(13, OUTPUT);
// initialize serial communications at 9600 bps:
Serial.begin(9600);
rfid.begin(9600); // Serial port for connection to RFID module
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.flush();
for( int i = 0; i < numSensors; i++ ) {
pinMode(pulsePin[i], INPUT);
digitalWrite(pulsePin[i], HIGH);
kickedCount[i] = 0;
lastPinState[i] = digitalRead(pulsePin[i]);
}
}
void loop() {
nowTime = millis();
pollPins();
if ( (nowTime - lastPourTime) > pourMsgDelay && lastPourTime > 0) {
//only send pour messages after all taps have stopped pulsing for a short period
//use lastPourTime=0 to ensure this code doesn't get run constantly
lastPourTime = 0;
checkPours();
checkKicks();
}
}
void pollPins() {
for ( int i = 0; i < numSensors; i++ ) {
int pinState = digitalRead(pulsePin[i]);
if ( pinState != lastPinState[i] ) {
if ( pinState == HIGH ) {
//separate high speed pulses to detect kicked kegs
if( nowTime - lastPinStateChangeTime[i] > 0 ){
pulseCount[i] ++;
}
else{
kickedCount[i] ++;
}
lastPinStateChangeTime[i] = nowTime;
lastPourTime = nowTime;
}
lastPinState[i] = pinState;
}
}
}
// Code to read the RFID Tag
void readRFID() {
while(rfid.available()>0)
{
tagValue[10] = rfid.read();
}
}
void checkPours() {
for( int i = 0; i < numSensors; i++ ) {
if ( pulseCount[i] > 0 ) {
if ( pulseCount[i] > 50 ) {
//filter out tiny bursts
// Returns the RFID value
readRFID();
sendPulseCount(tagValue[10], pulsePin[i], pulseCount[i]);
//Serial.print(reads);
//Serial.print(pulsePin[i]);
//Serial.print(pulseCount[i]);
}
pulseCount[i] = 0;
}
}
}
void checkKicks() {
for( int i = 0; i < numSensors; i++ ) {
if ( kickedCount[i] > 0 ) {
if ( kickedCount[i] > 30 ) {
//if there are enough high speed pulses, send a kicked message
sendKickedMsg(0, pulsePin[i]);
}
//reset the counter if any high speed pulses exist
kickedCount[i] = 0;
}
}
}
void sendPulseCount(char reads, int pinNum, unsigned int pulseCount) {
Serial.print("P;");
Serial.print(reads);
Serial.print(";");
Serial.print(pinNum);
Serial.print(";");
Serial.println(pulseCount);
}
void sendKickedMsg(uint8_t addr, int pinNum) {
Serial.print("K;");
Serial.print(addr);
Serial.print(";");
Serial.println(pinNum);
}
The code checks ok and uploads fine, but I can't seem to get the RFID Value passed to the python script... any ideas? or am I trying to do something that can't be done?