Arduino R4 hidden easter egg!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
one of the first things I noticed unboxing the new Arduino R4 was this cute heart-shaped pad on the back of the board I didn't think too much about it until I took a closer look at the schematic and I noticed this interesting net connecting pin 204 to label love and sure enough when I took a closer look at the heart-shaped pad I noticed a little Trace going to a via that connects to the microcontroller the same Trace is also present on the Arduino R4 Wi-Fi but instead of being connected to pin 204 which is being used for the LED matrix it's instead tied to pin 113. so that got me wondering why Arduino would have gone through with connecting this pad to one of the input pins on the microcontroller unlike the previous Arduino Uno boards which use the atmega328p microcontroller the Arduino R4 family uses the ra4 M1 microcontroller which comes with a 32-bit arm processor as well as a whole host of new peripherals and to make sense of the new chip we'll need to take a look at the ra4 M1 data sheet which is just a little bit of Light reading at 1436 pages the most helpful section I found is in i o ports under peripheral settings for each product which describes all of the alternate settings for each of the i o pens so if we take a look at table 19.7 we can see that for our pin 113 which is the love palette on the Wi-Fi board we see that it has four alternative functions the general pwm timer the capacitive touch sensing unit the segment LCD controller and the serial sound interface then if we go to table 19.8 on page 367 then we can see that for pin 204 which is the love pin on the Minima version there's a lot more peripherals but the most interesting of these is again the capacitive touch sensing unit the capacitive touch sensing unit is a peripheral that allows you to create keypads using touch electrodes hooked up to the microcontroller unfortunately there isn't yet an Arduino library that makes use of the capacitive touch unit and when I tried to set the registers manually I found it pretty confusing and I didn't get very far with it so hopefully someone smarter will come along and figure this out however there is an alternative way to play around with these pens and that's to use them as just a regular i o pen however because they aren't regular Arduino pins we won't be able to make use of the digital read digital write and pin mode functions let's use the debounce sketch from the Arduino IDE if we go to examples digital and debalance now this sketch was designed to make use of a push button attached from pin 2 to 5 volts and a 10 kilo ohm pull-down resistor attaching pin 2 to ground but we're going to change that up first off let's get rid of this button pin definition so instead we need to go to this section 19 on i o ports and take a look at setting the registers manually the relevant section in the data sheet is 19.2.5 on page 357 which describes a register named pmn PFS and the relevant bits that we need to set are bit to the port Direction which needs to be set to a zero for an input pin bit 4 for pull-up control which we want to enable as an input pull-up and finally if we read from bit 1 or pidr this will tell us if the value of the input pin is high or low now because we need different behavior for the two boards I'm going to use preprocessor definitions first if defined Arduino Minima and second if defined Arduino Uno Wi-Fi R4 so what I'm going to do is Define lovepin as register R PFS Port 2 pin 4 followed by the register pmn PFS underscore B and similarly for the Wi-Fi I use lovepin rpfs Port 1 pin 13. now if we go down to setup instead of using pin mode to configure the button pin we'll type lovepen dot PDR for the direction register equals zero to configure it as an input followed by love pin dot PCR equals one to configure the pull-up resistor then we go down to the loop function and we replace digital read with lovepin DOT Port input data register now because the sketch was designed for a switch with a pull down resistor but here we're using a pull-up resistor we need to change the initial button state from low to high then we need to go down to the loop function and change this button state check from high to low and just for fun I'm going to go into the setup function called serial dot begin and wait for it to initialize and then back down in the loop function where we toggle the button state I'm going to add a message serial dot print line open source is and then I'll add a little blue Emoji heart now we can go to compile the sketch and upload it to the Arduino R4 and open up the serial monitor so what we'll do is we'll take a jumper wire and attach it to the ground pin and then we can touch the other end of the jumper wire to the heart pad to close the switch then just for fun we can make it into a real button by adding a piece of aluminum foil so this example might seem a little contrived but I think it would be awesome if someone could figure out how to make these work as capacitive touch pads and short of that it would also be simple to solder a jumper wire here if you need access to an extra i o pen next up I'll be taking a look at the Led Matrix on the Wi-Fi version of the R4 let me know in the comments down below about any other features you'd like to see on the new Arduino boards if you enjoyed this video please give a like And subscribe and as always thanks for watching foreign
Info
Channel: Trevor Makes
Views: 69,762
Rating: undefined out of 5
Keywords: Arduino
Id: 5cS-ShyYW_k
Channel Id: undefined
Length: 6min 43sec (403 seconds)
Published: Fri Jun 30 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.