How to activate an external switch?


Bonjour from France.
I received my M2 and could start to program it (withArduino’s IDE, after a complete reinstall).
I am planning to use it on my wife’s car (this a Peugeot ion, similar to Mitsubishi imiev) to activate a “bird’s view” system automatically at very low speed (<10km/h).
I have already this functionality on my car (Rav4h), and my wife wants the same on her car…
The birdview system is already installed by myself.
I know how to interact with this thing.
I know exactly how to filter & extract the speed from the canbus (11bits @500k) on this car. Sometime ago I wrote a program for this model (it is on playstore, called canion).
My question: is how to activate one of the GPIOs to create a 12V signal?
Technically, I will use an optocoupler, but how to programmatically could I proceed?
Thx for any feedbacks.

1 Like

I can’t help with any specifics (since I don’t know them), but if you have not already found it from the Showcase, you probably will be interested in this library for the 12V IO.


Thank you…
This is exactly what I was looking for…


Have Updated M2_12VIO library to included PWM support as well as optional support to function with M2RET.
When functioning in unison with M2RET the library will use newer functions contained in M2RET

  1. Include the new ADC/DMA functionality in M2_12VIO when used as stand alone, 10% complete
  2. Finish 3 modes of Sleep & wake up along with detecting when to sleep. 40% complete

What is the range for the ADC for the M2_12VIO? Is it just 0-12 volts? Thinking about using the input to read in the battery voltage but if it goes from 0-12 volts I may need to include a voltage divider to drop the voltage into readable range.



Battery voltage is already available within the Macchina M2 without using any of the external I/O.
To be able to get correct readings you will need to remove the protection Zener diode D2 from the processor card as it currently starts conducting to early & effects the readings. After removal the Voltage readings returned in mVolts is extremely accurate for our purposes. It is reasonably safe to remove the protection diode as the maximum settings from the resistor voltage divider network on this pin are set for a maximum of 16.8V. In future revisions of this card D2 could be deleted & the VIN to this resistor network (R34/R38) could be moved to behind the FET Q1thus offering more protection to this pin providing D1, Q2, Q1 do not damp the supply volts before overvoltage kiks in. The Macchina designer techs are looking at this for possible future revisions.

In the M2_12VIO library look at function Supply_Volts().