8. Embedded programming¶
This week’s individual assignment is; - read a microcontroller data sheet - program your board to do something, with as many different programming languages and programming environments as possible
For the assignments, I created programs with Arduino language and C language for my board produced two weeks ago in the local sessions by referring to examples in Arduino and example created by my instructor.
I worked on RaspberryPi Pico in Group assignment for comparison in our group.
My board¶
My board has a LED light and a button. LED used PA07, Button PA06 pin.
DigiKey Data Sheet of ATTINY412¶
I have read and referred to the datasheet to know coding expressions during my programming exercises.
Programming - Arduino language¶
Arduino settings - Add additional Board in Preference http://drazzy.com/package_drazzy.com_index.json - Select a group including ATtiny412 in Board Manager - Select chip ATtiny412 - Select Programmer Serial Port pyupdi style - Select Port as confirmed by a command line /dev | grep -i usb in terminal.
Blink LED¶
Open Blink in Example of Arduino and modified for my board. Pin number identified from the Pinout chart. Since LED used PA7, Pin number of PWM was “1”. The example code uses a variable about PIN as LED_BUILTTIN but for me, defined Pin Number using Const int LedPin= 1.
The program verified, uploaded to my board and properly worked.
Press button and Blink LED¶
Starting from an example of button of Arduino. Incorporated Blink Program above.
Tried to do different way of coding by referring ATtiny412 data sheet. Per our instructor, with this coding compile and upload would be faster that that of Arduino IDE.
Blink was successfully uploaded and worked as expected.
Button and blink
The program was complied without error but didn’t work. Probably If expression underlined in green had problem. However this case was good for me to teach me how to read Data sheet.
Programming - C language¶
After the Saturday’s local session, our instructor presented an example of program used C language. It was written for ATtiny1614. I tried it with some adjustments for my ATtiny412. I’d like to write steps down I did for this programming for future references.
Pin numbers were replaced with mine. PA6 is connected to Switch button, PA7 is to LED. Using PA[N] of Datasheet because code written in resistor, not same as PWM number used in Arduino.
Step 1 : Check Serial USB Serial Port¶
shinobuishimura@ShinobunoMacBook-Air ~ % ls /dev | grep -i usb
cu.usbserial-D307RG9R
tty.usbserial-D307RG9R
Step 2 : See if 412.simpleblink.c & t412.simpleblink.c.ino is saved under the build folder¶
shinobuishimura@ShinobunoMacBook-Air ~ % cd arduino
shinobuishimura@ShinobunoMacBook-Air arduino % cd build
shinobuishimura@ShinobunoMacBook-Air build % ls
build.options.json t412.simpleblink.c
compile_commands.json t412.simpleblink.c.ino
Step 3 : Compile¶
shinobuishimura@ShinobunoMacBook-Air build % arduino-cli compile --fqbn megaTinyCore:megaavr:atxy4 --build-path ~/Arduino/build t412.simpleblink.c -v
Step 4 : Confirm *hex file created under the build holder.¶
shinobuishimura@ShinobunoMacBook-Air build % ls ~/Arduino/build/*hex
/Users/shinobuishimura/Arduino/build/t412.simpleblink.c.ino.hex
shinobuishimura@ShinobunoMacBook-Air build % ls
build.options.json t412.simpleblink.c
compile_commands.json t412.simpleblink.c.ino.bin
core t412.simpleblink.c.ino.eep
includes.cache t412.simpleblink.c.ino.elf
libraries t412.simpleblink.c.ino.hex
preproc t412.simpleblink.c.ino.lst
sketch
Step 5 : Instrall pyupdi.py¶
Tried programing but failed due to No pyupdi.py
shinobuishimura@ShinobunoMacBook-Air build % ls ~/Arduino/build/*hex
/Users/shinobuishimura/Arduino/build/t412.simpleblink.c.ino.hex
shinobuishimura@ShinobunoMacBook-Air build % pyupdi.py -d tiny412 -c /dev/tty.usbserial-D307RG9R -b 57600 -f t412.simpleblink.c.ino.hex
zsh: command not found: pyupdi.py
Step 5-1 : Create virtual environment -env1¶
shinobuishimura@ShinobunoMacBook-Air ~ % python3 -m venv env1
Step 5-2 : Activate env1, shown as (env1) if successfully activated¶
shinobuishimura@ShinobunoMacBook-Air ~ % source ~/env1/bin/activate
Step 5-3 : pip install¶
(env1) shinobuishimura@ShinobunoMacBook-Air ~ % pip install https://github.com/mraardvark/pyupdi/archive/master.zip
Detailed lines of PIP Instrall
Step 6 : Upload - Programming t412simpleblink.c.ino.hex to my board¶
(env1) shinobuishimura@ShinobunoMacBook-Air ~ % cd ~/Arduino/build
(env1) shinobuishimura@ShinobunoMacBook-Air build % pyupdi -d tiny412 -c /dev/tty.usbserial-D307RG9R -b 57600 -f t412.simpleblink.c.ino.hex
Device info: {'family': 'tinyAVR', 'nvm': 'P:0', 'ocd': 'D:0', 'osc': '3', 'device_id': '1E9223', 'device_rev': '0.1'}
Programming successful
Result