You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After I changed the code with temperature sensor to waterflow sensor the code stops running after the first loop. The first reading is send to TTN, but not the following readings because the loop got stuck.
Waterflow sensor is YF-402.
The port used is farthest from the Marvin LoRa USB.
Program: Arduino
Board: Arduino Leonardo
Can you guys explain what has happened to the loops?
The code I use is as follows:
/*
MarvinBase
Basic controls of IoT Academy Marvin LoRa Development board.
This version supports:
Sending LoRa uplink messages using ABP
Blink three times when sending data
Power control to RN2483 module
Instructions:
Get the latest version of the Arduino software
In Arduino IDE select Arduino Leonardo and com port of your device
Please adjust ABP adresses and key below to match yours
The loop() is where the actual stuff happens. Adjust input of send_lora_data() in void loop() to send your own data.
*/
/// #include <CayenneLPP.h> //App integratie
/// CayenneLPP lpp(51); //Buffergrootte in bytes
// Port to assign the type of lora data (any port can be used between 1 and 223)
int set_port = 1;
// Some standard ports that depend on the layout of the Marvin
long defaultBaudRate = 57600;
int reset_port = 5;
int RN2483_power_port = 6; //Note that an earlier version of the Marvin doesn't support seperate power to RN2483
int led_port = 13;
int flowPin = 39; //This is the input pin on the Arduino
float flowRate; //This is the value we intend to calculate.
volatile float count; //This integer needs to be set as volatile to ensure it updates correctly during the interrupt process.
//*** Set parameters here BEGIN ---->
String set_nwkskey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // Make sure you use your keys from TTN here
String set_appskey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
String set_devaddr = "XXXXXXXX";
//*** <---- END Set parameters here
/*
Setup() function is called when board is started. Marvin uses a serial connection to talk to your pc and a serial
connection to talk to the RN2483, these are both initialized in seperate functions. Also some Arduino port are
initialized and a LED is called to blink when everything is done.
*/
void setup() {
Serial.begin(defaultBaudRate);
Serial1.begin(defaultBaudRate);
InitializeSerials(defaultBaudRate);
initializeRN2483(RN2483_power_port, reset_port);
pinMode(led_port, OUTPUT); // Initialize LED port
blinky();
pinMode(flowPin, INPUT); //Sets the pin as an input
attachInterrupt(0, Flow, RISING); //Configures interrupt 0 (pin 2 on the Arduino Uno) to run the function "Flow"
Serial.begin(9600); //Start Serial
}
void loop() {
count = 0; // Reset the counter so we start counting from 0 again
interrupts(); //Enables interrupts on the Arduino
delay (1000); //Wait 1 second
noInterrupts(); //Disable the interrupts on the Arduino
//Start the math
flowRate = (count / 4.380); //Take counted pulses in the last second and multiply by 98
flowRate = flowRate * 60; //Convert seconds to minutes, giving you mL / Minute
flowRate = flowRate + 0.5;
int mL_min = (int)flowRate;
void initializeRN2483(int pwr_port, int rst_port)
{
//Enable power to the RN2483
pinMode(pwr_port, OUTPUT);
digitalWrite(pwr_port, HIGH);
print_to_console("RN2483 Powered up");
delay(1000);
void blinky()
{
digitalWrite(led_port, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(led_port, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(led_port, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(led_port, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
}
The text was updated successfully, but these errors were encountered:
Hi Githubbers,
Today I tried to connect Marvin LoRa device with The Things Network, fortunaly with basic program from https://github.com/iotacademy/marvin/blob/master/Software/MarvinBase/MarvinBase.ino allows me to connect to The Things Network (Keys are changed to the ones I use with TTN).
After I changed the code with temperature sensor to waterflow sensor the code stops running after the first loop. The first reading is send to TTN, but not the following readings because the loop got stuck.
Waterflow sensor is YF-402.
The port used is farthest from the Marvin LoRa USB.
Program: Arduino
Board: Arduino Leonardo
Can you guys explain what has happened to the loops?
The code I use is as follows:
/*
MarvinBase
Basic controls of IoT Academy Marvin LoRa Development board.
This version supports:
Sending LoRa uplink messages using ABP
Blink three times when sending data
Power control to RN2483 module
Instructions:
Get the latest version of the Arduino software
In Arduino IDE select Arduino Leonardo and com port of your device
Please adjust ABP adresses and key below to match yours
The loop() is where the actual stuff happens. Adjust input of send_lora_data() in void loop() to send your own data.
*/
/// #include <CayenneLPP.h> //App integratie
/// CayenneLPP lpp(51); //Buffergrootte in bytes
// Port to assign the type of lora data (any port can be used between 1 and 223)
int set_port = 1;
// Some standard ports that depend on the layout of the Marvin
long defaultBaudRate = 57600;
int reset_port = 5;
int RN2483_power_port = 6; //Note that an earlier version of the Marvin doesn't support seperate power to RN2483
int led_port = 13;
int flowPin = 39; //This is the input pin on the Arduino
float flowRate; //This is the value we intend to calculate.
volatile float count; //This integer needs to be set as volatile to ensure it updates correctly during the interrupt process.
//*** Set parameters here BEGIN ---->
String set_nwkskey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // Make sure you use your keys from TTN here
String set_appskey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
String set_devaddr = "XXXXXXXX";
//*** <---- END Set parameters here
/*
Setup() function is called when board is started. Marvin uses a serial connection to talk to your pc and a serial
connection to talk to the RN2483, these are both initialized in seperate functions. Also some Arduino port are
initialized and a LED is called to blink when everything is done.
*/
void setup() {
Serial.begin(defaultBaudRate);
Serial1.begin(defaultBaudRate);
InitializeSerials(defaultBaudRate);
initializeRN2483(RN2483_power_port, reset_port);
pinMode(led_port, OUTPUT); // Initialize LED port
blinky();
pinMode(flowPin, INPUT); //Sets the pin as an input
attachInterrupt(0, Flow, RISING); //Configures interrupt 0 (pin 2 on the Arduino Uno) to run the function "Flow"
Serial.begin(9600); //Start Serial
}
void loop() {
count = 0; // Reset the counter so we start counting from 0 again
interrupts(); //Enables interrupts on the Arduino
delay (1000); //Wait 1 second
noInterrupts(); //Disable the interrupts on the Arduino
//Start the math
flowRate = (count / 4.380); //Take counted pulses in the last second and multiply by 98
flowRate = flowRate * 60; //Convert seconds to minutes, giving you mL / Minute
flowRate = flowRate + 0.5;
int mL_min = (int)flowRate;
Serial.println(mL_min);
delay(100);
send_LoRa_data(set_port, String(mL_min));
blinky();
delay(1000);
read_data_from_LoRa_Mod();
delay(3000);
}
void Flow()
{
count++; //Every time this function is called, increment "count" by 1
}
void InitializeSerials(int baudrate)
{
delay(1000);
print_to_console("Serial ports initialised");
}
void initializeRN2483(int pwr_port, int rst_port)
{
//Enable power to the RN2483
pinMode(pwr_port, OUTPUT);
digitalWrite(pwr_port, HIGH);
print_to_console("RN2483 Powered up");
delay(1000);
//Disable reset pin
pinMode(rst_port, OUTPUT);
digitalWrite(rst_port, HIGH);
//Configure LoRa module
send_LoRa_Command("sys reset");
read_data_from_LoRa_Mod();
send_LoRa_Command("radio set crc off");
delay(1000);
read_data_from_LoRa_Mod();
send_LoRa_Command("mac set nwkskey " + set_nwkskey);
read_data_from_LoRa_Mod();
send_LoRa_Command("mac set appskey " + set_appskey);
read_data_from_LoRa_Mod();
send_LoRa_Command("mac set devaddr " + set_devaddr);
read_data_from_LoRa_Mod();
//For this commands some extra delay is needed.
/// send_LoRa_Command("mac set adr on");
/// delay(1000);
/// read_data_from_LoRa_Mod();
send_LoRa_Command("mac save");
delay(1000);
read_data_from_LoRa_Mod();
send_LoRa_Command("mac join abp");
delay(1000);
read_data_from_LoRa_Mod();
}
void print_to_console(String message)
{
Serial.println(message);
}
void read_data_from_LoRa_Mod()
{
if (Serial1.available()) {
String inByte = Serial1.readString();
Serial.println(inByte);
}
}
void send_LoRa_Command(String cmd)
{
print_to_console("Now sending: " + cmd);
Serial1.println(cmd);
delay(500);
}
void send_LoRa_data(int tx_port, String rawdata)
{
send_LoRa_Command("mac tx uncnf " + String(tx_port) + String(" ") + rawdata);
}
void blinky()
{
digitalWrite(led_port, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(led_port, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(led_port, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(led_port, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
}
The text was updated successfully, but these errors were encountered: