Can not get PN532 and mcp2515 to work together on arduino - arduino

I am trying to make the PN532 NFC reader module and mcp2515 to work together.
This is my code:
#include <SPI.h>
#include <mcp2515.h> //Library for using CAN Communication
#include <PN532_SPI.h>
#include <PN532.h>
#include <NfcAdapter.h>
#define deviceAddress 0x42
struct can_frame canMsg;
MCP2515 mcp2515(10);
PN532_SPI pn532spi1(SPI, 5);
PN532_SPI pn532spi2(SPI, 6);
NfcAdapter nfc1 = NfcAdapter(pn532spi1);
NfcAdapter nfc2 = NfcAdapter(pn532spi2);
void setup(void) {
Serial.begin(9600);
Serial.println("Starting...");
mcp2515.reset();
mcp2515.setBitrate(CAN_10KBPS, MCP_8MHZ);
mcp2515.setNormalMode();
delay(100);
nfc1.begin();
delay(100);
nfc2.begin();
}
void sendMessage(int data) {
canMsg.can_id = deviceAddress;
canMsg.can_dlc = 1;
canMsg.data[0] = data;
mcp2515.sendMessage(&canMsg);
}
void loop() {
if (nfc1.tagPresent())
{
Serial.println("Kattenhoofd");
NfcTag tag1 = nfc1.read();
if (tag1.getUidString() == "6C 1A D6 B9") {
Serial.println("YASSS!!!");
}
}
if (nfc2.tagPresent())
{
Serial.println("Konijnenvoet");
NfcTag tag2 = nfc2.read();
if (tag2.getUidString() == "59 07 CA 5C") {
Serial.println("YASSS!!!");
}
}
if (mcp2515.readMessage(&canMsg) == MCP2515::ERROR_OK) {
Serial.println("RECEIVED");
}
}
When I try this the two NFC readers only read the value once and then stop reading the tag.
Is there something wrong with my code? All the wiring is done correctly.
When I remove the mcp2515 and it initializations the nfc readers work as expected.

Related

How to fix "aes128_enc_single' was not declared in this scope"

I am connecting a sensor to android device through arduino. I need to encrypt my sensor data and then send it to android device. But when I include aes128_enc_single(key, temp), It gives an error and said "aes128_enc_single' was not declared in this scope "
What should I do for this?
I have included AESLib.h library
My sample code is
#include <SoftwareSerial.h>
#include <Adafruit_Sensor.h>
#include <AESLib.h>
uint8_t key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};
SoftwareSerial blue(2,3);
int i = 0;
float temp = 0;
void setup() {
Serial.begin(9600);
blue.begin(9600);
}
void loop() {
i = analogRead(A0);
temp = (i/1024.0)*500;
Serial.println(temp);
aes128_enc_single(key, temp);
Serial.print("encrypted:");
Serial.println(temp);
blue.print("Encrypted Temperature: ");
blue.println(temp);
delay(1000);
}

Hello World With NRF24L01

I have Arduino and a Duinotech NRF24L01, I am trying to send the string "Hello world" with maniacs bug RF24 library however, I think it cannot detect the incoming RF signal.
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
RF24 radio(7, 8); // CE, CSN
const uint64_t pipe = 0xF0F0F0F0E1L;
void setup() {
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, pipe);
radio.startListening();
}
void loop() {
if (radio.available()) {
char text[32] = "";
radio.read(&text, sizeof(text));
Serial.println(text);
}
else {
Serial.println("Data was not found");
}
In the read code, it would always execute data was not found. This makes me think that maybe it does not find the RF signal at all.
Here is the code that writes the data.
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
RF24 radio(7, 8); // CE, CSN
int text = 1;
const uint64_t pipe = 0xF0F0F0F0E1LL;
void setup() {
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
radio.stopListening();
}
void loop() {
radio.write(&text, sizeof(text));
Serial.println("Sending Data");
delay(1000);
}
Try this
For the transmitter Instead of const uint64_t pipe = 0xF0F0F0F0E1LL; use const byte address[6] = "00001"; as the address and then have you void setup like the code below
void setup() {
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
Then ensure that you have a value set for the test variable to be transmitted as below
void loop() {
const char text[] = "Hello World";
radio.write(&text, sizeof(text));
Serial.println("Sending Data");
delay(1000);
}
At the receiver end have this code running
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
void setup() {
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
}
void loop() {
if (radio.available()) {
char text[32] = "";
radio.read(&text, sizeof(text));
Serial.println(text); //This will print out the received value
}
}
PS: Ensure that all the connections are done to the right pins
AND you can test if the NRF24L01 chip is connected correctly by adding the code below
bool result = radio.isChipConnected ();
Serial.println (result);
it should print out a 1 to the serial monitor if the NRF24L01 chip is connected correctly

Code works on NodeMCU 1.0 but not on ESP8266 12E

I have a NodeMCU 1.0 and a ESP8266 12-E I created some code to check a GPS signal and report back, on the NodeMCU the code works 100% no problems but when I load the code on a ESP8266 12-e (with NodeMCU flashed on it) I can not get the GPS signal to show up wired to the same GPOI ports and everything.
Most of the code:
#include <TimGPS.h>
#include <SoftwareSerial.h >
#include "FS.h"
extern "C" {
#include "gpio.h"
#include "user_interface.h"
}
static const int RXPin = 12, TXPin = 255;
static const uint32_t GPSBaud = 9600;
TimGPS gps;
SoftwareSerial ss(RXPin, TXPin);
void printGPSData()
{
Serial.print("Latitude : ");
Serial.println(gps.location.lat(), 6);
Serial.print("Longitude : ");
Serial.println(gps.location.lng(), 6);
Serial.print("Speed : ");
Serial.println(gps.speed.mph(), 6);
Serial.print("Satellites: ");
Serial.println(gps.satellites.value());
Serial.print("Time UTC : ");
Serial.print(gps.time.hour());
Serial.print(":");
Serial.print(gps.time.minute());
Serial.print(":");
Serial.println(gps.time.second());
}
static void smartDelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (ss.available())
gps.encode(ss.read());
} while (millis() - start < ms);
}
void setup() {
Serial.begin(115200);
Serial.println("Startup");
ss.begin(GPSBaud);
}
void loop() {
if (millis() > 5000 && gps.charsProcessed() < 10) {
Serial.println(F("No GPS data received: check wiring"));
}
else
{
printGPSData(url);
}
}

communicating arduino to the other Arduino using RF24 getting the wrong result

I use these codes to transfer hello worlds but i just receive
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
in the receiver.
I don't understand what is the problem.
*******************Transmitter code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8);
const byte rxAddr[6] = "00001";
void setup()
{
radio.begin();
radio.setRetries(15, 15);
radio.openWritingPipe(rxAddr);
radio.stopListening();
}
void loop()
{
const char text[] = "Hello World";
radio.write(&text, sizeof(text));
delay(1000);
}
*****************receiver code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8);
const byte rxAddr[6] = "00001";
void setup()
{
while (!Serial);
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, rxAddr);
radio.startListening();
}
void loop()
{
if (radio.available())
{
char text[32] = {0};
radio.read(&text, sizeof(text));
Serial.println(text);
}
}
On the sending site you use:
const char text[] = "Hello World";
radio.write(&text, sizeof(text));
On the receiver site:
char text[32] = {0};
radio.read(&text, sizeof(text));
Are the both sizeof(text) equals?
In the sending part text is 11 bytes
In the receiving part text is 32 bytes

Arduino: loop function runs only once

I'm trying to request temperatures from my DS18B20 sensor to post on plot.ly, but it seems my loop function is only running once; after connecting to plot.ly and creating the graph, the temperature is printed once in the serial monitor and does not seem to continue! Any help is greatly appreciated. Here is my code:
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <plotly_streaming_cc3000.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define WLAN_SSID "wifi"
#define WLAN_PASS "********"
#define WLAN_SECURITY WLAN_SEC_WPA2
OneWire oneWire(10);
DallasTemperature sensors(&oneWire);
#define nTraces 1
char *tokens[nTraces] = {"token"};
plotly graph("username", "token", tokens, "filename", nTraces);
void wifi_connect(){
/* Initialise the module */
Serial.println(F("\n... Initializing..."));
if (!graph.cc3000.begin())
{
Serial.println(F("... Couldn't begin()! Check your wiring?"));
while(1);
}
// Optional SSID scan
// listSSIDResults();
if (!graph.cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
Serial.println(F("Failed!"));
while(1);
}
Serial.println(F("... Connected!"));
/* Wait for DHCP to complete */
Serial.println(F("... Request DHCP"));
while (!graph.cc3000.checkDHCP())
{
delay(100); // ToDo: Insert a DHCP timeout!
unsigned long aucDHCP = 14400;
unsigned long aucARP = 3600;
unsigned long aucKeepalive = 10;
unsigned long aucInactivity = 20;
if (netapp_timeout_values(&aucDHCP, &aucARP, &aucKeepalive, &aucInactivity) != 0) {
Serial.println("Error setting inactivity timeout!");
}
}
}
void setup() {
graph.maxpoints = 100;
Serial.begin(9600);
sensors.begin();
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
wifi_connect();
bool success;
success = graph.init();
if(!success){while(true){}}
graph.openStream();
}
void loop(void) {
Serial.print("Requesting temperatures...");
sensors.requestTemperatures();
Serial.println("DONE");
Serial.print("Temperature for Device 1 is: ");
Serial.print(sensors.getTempFByIndex(0));
graph.plot(millis(), sensors.getTempFByIndex(0), tokens[0]);
delay(500);
}

Resources