1

Over the past few months, I've been working on a wearable computer mouse using an Arduino and a 9-dof sensor. Most of the sketch is complete, and works as expected.

Recently, I started investigating how to enable a non-technical user to adjust the sensitivity of the device. Currently, I do this by changing a couple of variables in the sketch. My goal is to be able to create a basic GUI, with some buttons (perhaps unsurprisingly), to accomplish the same.

Requirements:

  • ability to adjust sensitivity (couple of variables inside sketch) of arduino device through a GUI
  • does not slow down sketch (I read that you can use serial, but wouldn't constantly checking for serial slow down the operation of the microcontroller?)
  • can be saved as an executable (easy to set up for a nonprogrammer)

It's fine for the solution to upload a new sketch to the microcontroller, or change variables in the EEPROM. Whatever you suggest is best. I came across this, and a few other similar topics, but due to my inexperience was unable to judge whether that's the best way forward.

I'm not looking for a complete solution, of course. Rather, I would really appreciate any guidance on what the basic "structure" of the solution should be. Then I can determine which parts I can do myself, and which I'll need to seek help on.

Thank you very much for looking at this.

5
  • As its a wearable mouse, how does it communicate with the PC? What Arduino are you using?
    – chrisl
    Nov 11 '21 at 9:39
  • There's 2 devices. A custom PCB handheld with the sensor, ATSAMD21 microprocessor, nrf24 module. That sends the information through the radio module to a USB dongle. The dongle has the same module, and uses the ATMEGA32U4. It has the arduino leonardo bootloader uploaded. Nov 11 '21 at 9:42
  • 1
    I guess your dongle is configured as HID device for the PC.
    – chrisl
    Nov 11 '21 at 9:46
  • 1
    I don't think this question should be closed. It is focused enough in my eyes. The OP already has some basic approaches and we just need explain the obvious misunderstandings. I was about to write an answer when the question was closed
    – chrisl
    Nov 11 '21 at 10:12
  • ok @chrisl, I still think it is too broad but if you can write an answer I reopened
    – Juraj
    Nov 11 '21 at 10:17
1

Reflashing (and with that recompiling) the sketch for every variable change is very over-the-top.

As you already want to write your own program for the PC I would suggest using Serial. That will be the easiest to implement. This would work like the following:

  • On the Arduino: You regularly check if there is data in the Serial buffer, read if in that case. You read until a newline character \n, which acts as message delimiter (to distinguish one message from the other). If a full message was received (meaning: you read the newline character) you process the message and write the new values to EEPROM (for saving them permanently).

  • On the PC application: Let the user determine each value. You open the Arduinos COM port (the user will have to select the correct one) to communicate via Serial. Then you send each value, that you want to write to the Arduino, in a specific format. For example <value_name>:<value>. And don't forget the newline character at the end. Then you can close the COM port and exit the application.

This requires the user to choose the corresponding COM port. With using a custom USB profile (I think a custom HID profile should also be able to receive data) you could eliminate that, but this is a big step in difficulty for you to program.

I read that you can use serial, but wouldn't constantly checking for serial slow down the operation of the microcontroller?

No, not really. The actual receiving of data is done by the USB hardware. As processing load you only have the placing of data in the buffer (happens inside an ISR), which only is done when actual data is received, and the checking if there is data in the buffer. That also needs very short time. It should not interfere with your sampling rate. The 9-DoF sensor is most likely way slower. The actual processing of the data is also only done when you actually send data. Here the longest will be saving the data in EEPROM.

So all in all you have little to no impact on performance.

9
  • Hi Chris, Thank you very much for taking the time to respond. This is what I was looking for; gives me a fairly good idea of the next steps of research to take. So for the arduino code, would I be writing the code that checks for serial data in a ISR? I'm not sure what you mean by: "As processing load you only have the placing of data in the buffer (happens inside an ISR), which only is done when actual data is received" Nov 11 '21 at 12:10
  • 1
    Do you know what interrupts and ISR are? If not I can include a short explanation about that
    – chrisl
    Nov 11 '21 at 12:47
  • 1
    @ZhelyazkoGrudov: Re “would I be writing the code that checks for serial data in a ISR?”: No. That ISR is provided by the Arduino core library. You would just have to check for Serial.available() within your loop(). Nov 11 '21 at 13:18
  • 1
    About ISR: The actual data receiving is done with ISRs in the background. You don't have to do anything with them (since that is all hidden in the Serial object). You only use Serial.available(), which checks if you have new data in the buffer. And as described: This works that fast, that it won't really change your performance. It just takes a few clock cycles. Your 9-DoF sensor will be way slower.
    – chrisl
    Nov 11 '21 at 15:25
  • 1
    Also: If it would make an impact, then you would get problems at other places too. The way to go in such a case would be to use a faster microcontroller. But you already have a fast microcontroller (depending on how you are clocking it on your PCB up to 48MHz). Checking Serial isn't a problem on the Uno, which is only 16MHz. You should try it out.
    – chrisl
    Nov 11 '21 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.