I am trying to figure out the simplest way to turn on/off the “CAN 5V” wire on the M8 connector on the Tracker One.
I saw that that it may be able to be called with CAN_PWR.
Triggering through the console would be fine for my initial prototyping.
Anyone know a good solution?
You can’t do it from the console with the default tracker edge firmware. However, from your own firmware you can turn it on using:
pinMode(CAN_PWR, OUTPUT);
digitalWrite(CAN_PWR, HIGH);
and turn it off with
digitalWrite(CAN_PWR, LOW);
You could do that from a Particle.function or a Particle edge command handler to do it remotely from the console if you needed to be able to do that with your firmware.
I am getting an out of scope error, not sure where I am going wrong.
Code below
#include "Particle.h"
#include "tracker_config.h"
#include "tracker.h"
SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(SEMI_AUTOMATIC);
PRODUCT_ID(TRACKER_PRODUCT_ID);
PRODUCT_VERSION(TRACKER_PRODUCT_VERSION);
SerialLogHandler logHandler(115200, LOG_LEVEL_TRACE, {
{ "app.gps.nmea", LOG_LEVEL_INFO },
{ "app.gps.ubx", LOG_LEVEL_INFO },
{ "ncp.at", LOG_LEVEL_INFO },
{ "net.ppp.client", LOG_LEVEL_INFO },
});
void setup()
{
Tracker::instance().init();
Particle.function("Relay", RelayControl);
pinMode(CAN_PWR, OUTPUT);
digitalWrite(CAN_PWR, LOW);
}
void loop()
{
Tracker::instance().loop();
}
int RelayControl(String command)
{
int state = LOW;
// find out the state of the relay
if(command == "HIGH"){
state = HIGH;
}else if(command == "LOW"){
state = LOW;
}else{
return -1;
}
// write to the appropriate pin
digitalWrite(CAN_PWR, state);
return 1;
}
Could you copy and paste the actual error?
c:/Users/XXX/tracker-edge//src/main.cpp: In function 'void setup()':
c:/Users/XXX/tracker-edge//src/main.cpp:39:32: error: 'RelayControl' was not declared in this scope
39 | Particle.function("Relay", RelayControl);
| ^~~~~~~~~~~~
make[3]: *** [../build/module.mk:274: ../build/target/user/platform-26-m/tracker-edge/src/main.o] Error 1
make[2]: *** [../../../build/recurse.mk:12: user] Error 2
make[1]: *** [../build/recurse.mk:12: modules/tracker/user-part] Error 2
make: *** [C:\Users\XXX\.particle\toolchains\buildscripts\1.9.2\Makefile:54: compile-user] Error 2
The terminal process "C:\Users\XXX\.particle\toolchains\buildtools\1.1.1\bin\bash.exe '-c', 'make -f 'C:\Users\XXX\.particle\toolchains\buildscripts\1.9.2\Makefile' compile-user -s'" terminated with exit code: 2.
Just add a function prototype before setup()
.
Normally that would be a C/C++ requirement anyway.
It’s only not required for the primary .ino
file in a project as this undergoes some pre-processing which - among other things - adds any missing prototypes.
But for .cpp
files it is/was always needed.
1 Like