Hi I was wondering if there is any way to/ how I might go about solving the following.

I am designing my own arduino board based on a mega32u4 chip and I want my arduino board to light up an indicator led depending on if an analog pin is in use. For example if a user uploads code that utilizes a certain pin say reading a voltage from A0, the arduino would light up an LED next to that pin.

I was thinking perhaps I could tie the analog pin to a digital pin in the firmware and have the digital pin go HIGH every time the analog pin is in use(is this possible/ could anyone point me to good examples online)?

The user needs to know whether or not the pin they think is writing is actually outputting a signal and/or if the pin they think is reading is reading a signal. This is beacause they will be hooking up outputs and inputs to the arduino board using conductive ink and if their circuit isnt working the indicator lights will let them know that their software is working but there is probably a break in the circuitry they drew out.

  • Sounds like you would like a LED per pin to indicate usage, mode, etc? You could do this with a shift register or GPIO port extender and then modify the Arduino core pinMode() and analogRead() so that the status is shown on the respective LED. If I remember correctly the mega32u4 has a few extra pins that are not used by the Arduino core. These could be used for the LED control. Aug 30 '18 at 21:49
  • 2
    First you will have to define "in use". Do you mean actively using analogRead(), or just that something is connected to the pin?
    – Majenko
    Aug 30 '18 at 21:49
  • It takes about 100 microseconds (0.0001 s) to read an analog input. So I doubt you can see the leds flash that fast.
    – Gerben
    Aug 31 '18 at 13:17
  • Mikael, this sounds like a feasible solution but could it be implemented behind the scenes such that the user does not see the code? Like I suppose I would have to implement my own modified core that the user would select my board in the tools>board menu. It feels like that might be bad practice to have those functions write to other pins (anyone want to weigh in?) but it is a solution.
    – Chris
    Aug 31 '18 at 14:55
  • Majenko, I was imagining that the user would have the pin mentioned in their code somewhere regardless of whether or not anything was connected. Would it be possible to have an indicator light turn on if something was connected (even if it was an input device)?
    – Chris
    Aug 31 '18 at 14:58

When you upload code that is the firmware. There isn't another lot of firmware (like an operating system) that is always there (excepting the bootloader which is only used for uploading new code).

Maybe you could connect an LED, via an op-amp as an amplifier, to the analog pin, so that if a voltage appears that it would light the LED. However it could be "in use" and reading zero volts so that wouldn't prove an enormous lot.

would it be ill advised to attempt a solution on the lines of what Mikael proposed in the comments?

You can make your own analogRead function and encourage your users to use it (or do it via a #define) however that will only work if people use your new function or header file.

It would also have the side-effect of making other pins not available (ie. the pins you are doing the LED on) which might be confusing for users who are trying to use all available pins.

I assume this is some sort of teaching gadget? It might be better to teach people to do an indicator LED themselves rather than trying to automate it for them.

  • Thanks for the clarification Nick, would it be ill advised to attempt a solution on the lines of what Mikael proposed in the comments?
    – Chris
    Aug 31 '18 at 14:58
  • See amended answer.
    – Nick Gammon
    Sep 2 '18 at 21:46

Create a library. User will include it and the h file will create a single instance of the handler object for your pin pairs. The handler will register a timer interrupt, and the interrupt will check the source pin and set the target pin.

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.