- Mon Jul 24, 2017 4:19 pm
#195651
I am having difficulty in understanding the use of digital pins in an arrangement based on a SparkFun RedBoard and SparkFun CAN-Bus shield. I am trying to develop a trap which will detect a particular CAN message ID with FF as the hex data at byte 4 and turn on an LED.
I am a complete newbie with Arduino and developing software for this environment and I don't know whether my coding is poor or I am being "caught" by a feature of the digital pins which I am failing to understand.
I have some code which works at detecting message ID 2DE with FF as data at the 4th byte and using an LED on pin 13 with the following code:
/****************************************************************************
Used for development of Nissan EPAS for Fraser deJoux
*************************************************************************/
#include <Canbus.h>
#include <defaults.h>
#include <global.h>
#include <mcp2515.h>
#include <mcp2515_defs.h>
const int ledPin = 13; //Led connected to pin 13
//********************************Setup Loop*********************************//
void setup() {
Serial.begin(9600); // For debug use
Serial.println("CAN Read - Testing receipt of CAN Bus message");
delay(1000);
pinMode(ledPin, OUTPUT); //Set digital pin 13 to OUTPUT
if(Canbus.init(CANSPEED_500)) //Initialise MCP2515 CAN controller at 500K
Serial.println("CAN Init ok");
else
Serial.println("Can't init CAN");
delay(1000);
}
//********************************Main Loop*********************************//
void loop(){
tCAN message;
if (mcp2515_check_message())
{
if (mcp2515_get_message(&message))
{
if(message.id == 0x2DE and message.data[4] == 0xFF) //Test for PID 2DE with data FF in the 4th byte
{
Serial.println("Error detected");
digitalWrite(ledPin, HIGH); //Set LED on
}
else
{
digitalWrite(ledPin, LOW); //Set LED off
}
}
}
}
Here is my problem: It all started with the observation that the light being emitted from the LED was very dim which I deduced was probably because it was being pulsed on and off with a rather low pulse width. So I elected to switch the LED to another pin and play with the code in an effort to improve the performance. But if I switch from pin 13 to pin 11 in the line of code in red text, it no longer works. The LED is hard on and stays on, meanwhile the serial monitor is telling me that my error message "Error detected" is only appearing when the error is present.
Something else is at work controlling pin 11 in spite of my coding..... What is my idiot mistake? I wonder whether the CAN-Bus shield is using this pin for something else. Do I have a hardware issue or a software issue? My attempts to research this and understand what is happening have come up empty so far.....
Any assistance would be appreciated
I am a complete newbie with Arduino and developing software for this environment and I don't know whether my coding is poor or I am being "caught" by a feature of the digital pins which I am failing to understand.
I have some code which works at detecting message ID 2DE with FF as data at the 4th byte and using an LED on pin 13 with the following code:
/****************************************************************************
Used for development of Nissan EPAS for Fraser deJoux
*************************************************************************/
#include <Canbus.h>
#include <defaults.h>
#include <global.h>
#include <mcp2515.h>
#include <mcp2515_defs.h>
const int ledPin = 13; //Led connected to pin 13
//********************************Setup Loop*********************************//
void setup() {
Serial.begin(9600); // For debug use
Serial.println("CAN Read - Testing receipt of CAN Bus message");
delay(1000);
pinMode(ledPin, OUTPUT); //Set digital pin 13 to OUTPUT
if(Canbus.init(CANSPEED_500)) //Initialise MCP2515 CAN controller at 500K
Serial.println("CAN Init ok");
else
Serial.println("Can't init CAN");
delay(1000);
}
//********************************Main Loop*********************************//
void loop(){
tCAN message;
if (mcp2515_check_message())
{
if (mcp2515_get_message(&message))
{
if(message.id == 0x2DE and message.data[4] == 0xFF) //Test for PID 2DE with data FF in the 4th byte
{
Serial.println("Error detected");
digitalWrite(ledPin, HIGH); //Set LED on
}
else
{
digitalWrite(ledPin, LOW); //Set LED off
}
}
}
}
Here is my problem: It all started with the observation that the light being emitted from the LED was very dim which I deduced was probably because it was being pulsed on and off with a rather low pulse width. So I elected to switch the LED to another pin and play with the code in an effort to improve the performance. But if I switch from pin 13 to pin 11 in the line of code in red text, it no longer works. The LED is hard on and stays on, meanwhile the serial monitor is telling me that my error message "Error detected" is only appearing when the error is present.
Something else is at work controlling pin 11 in spite of my coding..... What is my idiot mistake? I wonder whether the CAN-Bus shield is using this pin for something else. Do I have a hardware issue or a software issue? My attempts to research this and understand what is happening have come up empty so far.....
Any assistance would be appreciated