Hi all,
So a little project backrground; I'm building a sensor which uses the arduino nano. It provides data to an application on my PC over serial. My sensor has two modes of operation and I would like to be able to toggle between them with a serial message triggered by my external application in a sort of closed loop system.
I guess the obvious answer for the arduino to register this message and switch modes would be using a SerialEvent. However, my thinking (could be wrong), is that this isn't ideal because one of the two modes is intended to be high bandwidth, so ideally I don't want to be jumping out of the main loop after every iteration to check the input buffer. And also I suppose I would have to have an if statement or switch/case sort of setup in main loop, which would presumably also lower the frequency...?
I have a read that it's possible to adapt the core code, specifically HardwareSerial.cpp so that instead of putting incoming bytes in the input buffer the interrupt handler can do something else. If I can set this up so that it switches the mode upon the interrupt I'm thinking I could essentially have the two modes operating and synchronously receive a signal from my pc to switch between them thus not compromising speed at all.
Is this feasible? I'm imagining there may be a problem in that the interrupt routine wouldn't be just a quick operation and it would need to looping continuously, I would then also need to be able to get out of the routine upon another signal from the PC...
Does anybody have any advice on the best way to go about this sort of thing?
Best,
Nick