<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://www.openhardwareconf.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Marcmerlin</id>
	<title>Open Hardware Miniconf - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://www.openhardwareconf.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Marcmerlin"/>
	<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/wiki/Special:Contributions/Marcmerlin"/>
	<updated>2026-04-11T09:09:54Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.44.1</generator>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1376</id>
		<title>Swagbadge2021 GettingStarted</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1376"/>
		<updated>2021-02-13T04:46:01Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Hardware pinout */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Getting started with the Swagbadge =&lt;br /&gt;
&lt;br /&gt;
== Support ==&lt;br /&gt;
* The [https://spectrum.chat/lca2021-swagbadge Swag Badge Spectrum chat] is a place where the badge team hangs out, ready to answer your questions.&lt;br /&gt;
&lt;br /&gt;
== My package arrived in the mail, first steps. ==&lt;br /&gt;
* Your package should contain your badge, and some other goodies! &lt;br /&gt;
** [[File:swagbadgepackage.jpg|400px|alt=Image showing the contents of the swagbag package]]&lt;br /&gt;
** Badge&lt;br /&gt;
** SAO headers (x 4)&lt;br /&gt;
** SAO proto boards (x 2)&lt;br /&gt;
** SAO tux board&lt;br /&gt;
** Lanyard&lt;br /&gt;
** Stickers&lt;br /&gt;
** Instructions&lt;br /&gt;
* Take off the protective cases to reveal the screens.&lt;br /&gt;
* Powering it up&lt;br /&gt;
** Insert a micro USB cable into the badge and connect the other end to a USB port on your computer or USB power source.&lt;br /&gt;
** A green light should glow on the rear of the board, and a title appear across the two screens.&lt;br /&gt;
* Turning it on and off again&lt;br /&gt;
** Plugging/unplugging it is fine. Usually the badge isn&#039;t running anything intensely enough that just unpowering it would cause a problem.&lt;br /&gt;
* On bootup, you should see:&lt;br /&gt;
** The OLED screens will display &amp;quot;Aiko&amp;quot; and a version number as a title&lt;br /&gt;
** It will also display something else to tell you to set up your wifi.&lt;br /&gt;
&lt;br /&gt;
== Getting it on your network ==&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - wireless ===&lt;br /&gt;
&lt;br /&gt;
The first time you boot your badge, it won&#039;t know how to talk to your wifi network, so it creates its own temporary wifi network for you to connect to, so you can configure it.&lt;br /&gt;
&lt;br /&gt;
* Start your badge by plugging it in.&lt;br /&gt;
* The screens on your badge will say &amp;lt;code&amp;gt;Configure WiFi:&amp;lt;/code&amp;gt; &lt;br /&gt;
   [[File:configurewifi-1.png|300px]]&lt;br /&gt;
* Use your phone (or computer) to change wifi networks to use the badge. The badge wifi name starts with &amp;lt;code&amp;gt;aiko&amp;lt;/code&amp;gt; followed by some numbers/letters. &lt;br /&gt;
   [[File:configurewifi-2.png|200px]] -&amp;gt; [[File:configurewifi-3.png|200px]]&lt;br /&gt;
* Once you&#039;re connected to the badge wifi, open a web browser on that device to the IP address shown on the screens. Something like &amp;lt;code&amp;gt;http://192.168.4.1&amp;lt;/code&amp;gt; &lt;br /&gt;
   [[File:configurewifi-5.png|300px]]&lt;br /&gt;
* You&#039;ll be prompted to enter your wifi SSID and wifi password. &#039;&#039;&#039;Note: Your device can only use a 2.4GHz network&#039;&#039;&#039;: it is not compatible with 5GHz WiFi.&lt;br /&gt;
* The badge will restart using the credentials you&#039;ve provided and it will shut down its wifi access point. &lt;br /&gt;
   [[File:configurewifi-4.png|300px]]&lt;br /&gt;
* Your phone/computer will go back to using its usual wifi network and badge is now online!&lt;br /&gt;
&lt;br /&gt;
Note: If you are using an Android device to link the badge to your WiFi, it will pop up a dialog to say you are switching to a network that doesn&#039;t have Internet access and ask if you want to switch back. Select &amp;quot;Keep&amp;quot; to stay on the badge&#039;s temporary access point.&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - commandline with mpfshell ===&lt;br /&gt;
&lt;br /&gt;
If the above guide to setting up via the wifi AP (access point) doesn&#039;t work, you can put a configuration file onto the badge. You&#039;ll need a Python environment to do so, which you&#039;ll need anyway if you plan on writing your own badge software applications.&lt;br /&gt;
&lt;br /&gt;
* Start by getting [[Swagbadge2021_UpdatingSoftware|a copy of the aiko firmware, and installing mpfshell]]&lt;br /&gt;
* &#039;&#039;Note: Your device can only talk to a 2.4GHz network: it is not compatible with 5GHz.&#039;&#039;&lt;br /&gt;
* Edit aiko_engine_mp/configuration/net.py and insert the details of your SSID and password.&lt;br /&gt;
* use mpfshell: &amp;lt;code&amp;gt;mpfshell -o COM3&amp;lt;/code&amp;gt; (substitute the com port/tty of your badge)&lt;br /&gt;
* &amp;lt;code&amp;gt;put configuration/net.py configuration/net.py&amp;lt;/code&amp;gt;&lt;br /&gt;
* fire up repl to view the console log &lt;br /&gt;
* You can now restart your device&lt;br /&gt;
* On bootup it should now talk to your network and you can see it on the console log.&lt;br /&gt;
&lt;br /&gt;
Your badge will display its connection status on the screens.&lt;br /&gt;
&lt;br /&gt;
= Running pre-installed applications =&lt;br /&gt;
&lt;br /&gt;
== Aiko&#039;s minimal Swagbadge application ==&lt;br /&gt;
At the moment the badge by default a basic &amp;quot;Swagbadge&amp;quot; application within the Aiko framework. This application&lt;br /&gt;
* has a thread to keep wifi running, &lt;br /&gt;
* has a thread to stay connected to (our Australian, private) mqtt server&lt;br /&gt;
* has a thread to display a rotating header across the two oleds.&lt;br /&gt;
&lt;br /&gt;
You can now talk to your badge [[Swagbadge2021_MQTT|using MQTT messages]].&lt;br /&gt;
&lt;br /&gt;
== Running other applications ==&lt;br /&gt;
At the moment, &amp;quot;swagbadge&amp;quot; is the only application that&#039;s for use with the badge. &lt;br /&gt;
&lt;br /&gt;
There are [https://github.com/geekscape/aiko_engine_mp/tree/master/applications other applications] in the repo which are for other places the Aiko framework has been used.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve written an application of your own and want to run that by default on badge startup, &lt;br /&gt;
# edit your local copy of configuration/main.py and change the value of the &amp;quot;application&amp;quot; to point to your new application.&lt;br /&gt;
# using mpfshell, &#039;put&#039; configuration/main.py and applications/your_application.py onto the badge&lt;br /&gt;
# Restart the badge&lt;br /&gt;
&lt;br /&gt;
== Running example code ==&lt;br /&gt;
There is [https://github.com/geekscape/aiko_engine_mp/tree/master/examples example code] which has a number of examples in it, including a snake game and a demo of how to use various badge functions.&lt;br /&gt;
&lt;br /&gt;
# From your commandline on your computer, use mpfshell to put whatever example code you want onto the badge.&lt;br /&gt;
# To run example code, you can use the &amp;quot;emergency stop&amp;quot; function to halt any other applications and put you in the repl.&lt;br /&gt;
## Touch both of the bottom spots on the sliders&lt;br /&gt;
## Reboot the badge&lt;br /&gt;
# Now at the repl prompt, type (replace the name of the module as appropriate for the code you want to run): &lt;br /&gt;
&lt;br /&gt;
Use examples.game_snake as example:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
from examples.game_snake import run&lt;br /&gt;
run()&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ctrl-c to halt operation and return to the repl prompt.&lt;br /&gt;
&lt;br /&gt;
= Hardware pinout =&lt;br /&gt;
&lt;br /&gt;
You can get the schematic and pin mapping on this page: https://github.com/CCHS-Melbourne/Swag-Badge/blob/master/swag-badge-schematic.pdf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- GPIO0 : left breakout pin4 (can be VSPI CS/SS#1 if 2 SPI devices, otherwise wire CS to GND)&lt;br /&gt;
- GPIO2 : left breakout pin3 (can be VSPI CS/SS#2 if 2 SPI devices, otherwise wire CS to GND)&lt;br /&gt;
&lt;br /&gt;
- GPIO4 : SCL (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO5 : SDA (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO12/15: slider #1&lt;br /&gt;
- GPIO13: left breakout pin3 (can be used for TFT backlight)&lt;br /&gt;
- GPIO14/27: slider #2&lt;br /&gt;
- GPIO16: left switch  (under screen #1)&lt;br /&gt;
- GPIO17: right switch (under screen #2)&lt;br /&gt;
&lt;br /&gt;
- GPIO18: SAO3 pin3 + LB pin7  (also VSPI SCL/SCK/CLK/D0)&lt;br /&gt;
- GPIO23: SAO3 pin4            (also VSPI SDA/SDI/MOSI/D1)&lt;br /&gt;
&lt;br /&gt;
- GPIO19: SAO1 pin4&lt;br /&gt;
- GPIO22: SAO1 pin3 (also onboard blue LED in the back)&lt;br /&gt;
&lt;br /&gt;
- GPIO21: unused but not wired on this chip&lt;br /&gt;
&lt;br /&gt;
- GPIO25: SAO4 pin4 + RB pin6  (also VSPI DC/A0/RS)&lt;br /&gt;
- GPIO26: SAO4 pin3 + RB pin7  (also VSPI RES/RST or RST can be wired to EN for auto)&lt;br /&gt;
&lt;br /&gt;
- GPIO32: SAO2 pin3 + RB pin4 (touch pin, can be used with SAO tux foot or nose touchpad) &lt;br /&gt;
- GPIO33: SAO2 pin4 + RB pin5 (touch pin, can be used with SAO tux foot or nose touchpad)&lt;br /&gt;
&lt;br /&gt;
- GPIO34: right breakout pin2 (input only)&lt;br /&gt;
- GPIO35: right breakout pin3 (input only)&lt;br /&gt;
&lt;br /&gt;
- GPIO36: unused but not wired on this chip (input only)&lt;br /&gt;
- GPIO39: unused but not wired on this chip (input only)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Hardware SPI for a device like SSD1331 ==&lt;br /&gt;
ESP32 has 2 DMA capable hardware SPI busses usable by the user: SPI2/HSPI and SPI3/VSPI (see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/spi_master.html and https://github.com/espressif/arduino-esp32/blob/master/libraries/SPI/examples/SPI_Multiple_Buses/SPI_Multiple_Buses.ino for how to use them at the same time ). The important note in the espressif doc is that if you do not use the dedicated default HWSPI pins, they get routed through a hardware MUX and your maximum SPI speed is lowered from 80Mhz to 40Mhz.&lt;br /&gt;
&lt;br /&gt;
If you would like to connect an SPI device like an SSD1331 96x64 color TFT, here are default hardware pin numbers, and pins you can use for non SPI signals (RES/RST, DC/A0/RS, and CS/SS):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  SD1331 Pin	        ESP32	ESP32&lt;br /&gt;
1 GND                   VSPI    HSPI &lt;br /&gt;
2 VCC&lt;br /&gt;
3 SCL/SCK/CLK/D0	18	14   &lt;br /&gt;
4 SDA/SDI/MOSI/D1	23	13   &lt;br /&gt;
---- 2 pins above and MISO are HWSPI, pins below are anything&lt;br /&gt;
---- RST is not part of SPI, it&#039;s an out of band signal to reset a TFT&lt;br /&gt;
---- This could be wired to the ESP32 EN(reset) pin&lt;br /&gt;
5 RES/RST		26	26   &lt;br /&gt;
---- Data/Command pin is not part of SPI but used to tell the TFT if incoming SPI&lt;br /&gt;
---- data is actually a command, or pixel data.&lt;br /&gt;
6 DC/A0/RS (data)	25	25   &lt;br /&gt;
---- Cable select chooses which SPI device we&#039;re talking to, if there is only&lt;br /&gt;
---- one, it can be tied to ground. Any pin is fine&lt;br /&gt;
7 CS/SS =&amp;gt; GND	        0	2   &lt;br /&gt;
&lt;br /&gt;
---- MISO is not used to talk to TFTs, and is a hardware pin, but unused here&lt;br /&gt;
  MISO		        19	12    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
pins 12/13/14 are already used by the badge, but 18/19/23 are usable (SAO3 and SAO1), and since MISO is unused, you could also assign it to GPIO21 which isn&#039;t wired at all on the lolin lite chip.  &lt;br /&gt;
If you&#039;d also like to keep SAO4 usable (25/26), you can wire CS/SS to ground to free up pin 27, move DC/AO/RS to pin 27, and free up pin 26 (RST) by wiring RST to the ESP32 ENA pin, which should issue a TFT reset every time the ESP32 is reset.&lt;br /&gt;
&lt;br /&gt;
End result: https://youtu.be/TYItVAa4tJY&lt;br /&gt;
&lt;br /&gt;
= Extensions: Adding a SAO =&lt;br /&gt;
* provided by others: look at [https://www.tindie.com/search/?q=SAO Tindie]&lt;br /&gt;
* [[Swagbadge2021_SAO|Build your own]]&lt;br /&gt;
&lt;br /&gt;
= Extensions: Writing your own applications =&lt;br /&gt;
&lt;br /&gt;
Between when we ship the board and when it arrives, there might be some changes to the software framework (Aiko). Here&#039;s how to update it. Or perhaps you&#039;re interested in writing your own applications? &lt;br /&gt;
&lt;br /&gt;
* [[Swagbadge2021_UpdatingSoftware|Updating the Software]]&lt;br /&gt;
* [[Swagbadge2021_SoftwareDev|Writing your own badge programs]]&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1375</id>
		<title>Swagbadge2021 GettingStarted</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1375"/>
		<updated>2021-02-13T04:30:36Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Using Hardware SPI for a device like SSD1331 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Getting started with the Swagbadge =&lt;br /&gt;
&lt;br /&gt;
== Support ==&lt;br /&gt;
* The [https://spectrum.chat/lca2021-swagbadge Swag Badge Spectrum chat] is a place where the badge team hangs out, ready to answer your questions.&lt;br /&gt;
&lt;br /&gt;
== My package arrived in the mail, first steps. ==&lt;br /&gt;
* Your package should contain your badge, and some other goodies! &lt;br /&gt;
** [[File:swagbadgepackage.jpg|400px|alt=Image showing the contents of the swagbag package]]&lt;br /&gt;
** Badge&lt;br /&gt;
** SAO headers (x 4)&lt;br /&gt;
** SAO proto boards (x 2)&lt;br /&gt;
** SAO tux board&lt;br /&gt;
** Lanyard&lt;br /&gt;
** Stickers&lt;br /&gt;
** Instructions&lt;br /&gt;
* Take off the protective cases to reveal the screens.&lt;br /&gt;
* Powering it up&lt;br /&gt;
** Insert a micro USB cable into the badge and connect the other end to a USB port on your computer or USB power source.&lt;br /&gt;
** A green light should glow on the rear of the board, and a title appear across the two screens.&lt;br /&gt;
* Turning it on and off again&lt;br /&gt;
** Plugging/unplugging it is fine. Usually the badge isn&#039;t running anything intensely enough that just unpowering it would cause a problem.&lt;br /&gt;
* On bootup, you should see:&lt;br /&gt;
** The OLED screens will display &amp;quot;Aiko&amp;quot; and a version number as a title&lt;br /&gt;
** It will also display something else to tell you to set up your wifi.&lt;br /&gt;
&lt;br /&gt;
== Getting it on your network ==&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - wireless ===&lt;br /&gt;
&lt;br /&gt;
The first time you boot your badge, it won&#039;t know how to talk to your wifi network, so it creates its own temporary wifi network for you to connect to, so you can configure it.&lt;br /&gt;
&lt;br /&gt;
* Start your badge by plugging it in.&lt;br /&gt;
* The screens on your badge will say &amp;lt;code&amp;gt;Configure WiFi:&amp;lt;/code&amp;gt; &lt;br /&gt;
   [[File:configurewifi-1.png|300px]]&lt;br /&gt;
* Use your phone (or computer) to change wifi networks to use the badge. The badge wifi name starts with &amp;lt;code&amp;gt;aiko&amp;lt;/code&amp;gt; followed by some numbers/letters. &lt;br /&gt;
   [[File:configurewifi-2.png|200px]] -&amp;gt; [[File:configurewifi-3.png|200px]]&lt;br /&gt;
* Once you&#039;re connected to the badge wifi, open a web browser on that device to the IP address shown on the screens. Something like &amp;lt;code&amp;gt;http://192.168.4.1&amp;lt;/code&amp;gt; &lt;br /&gt;
   [[File:configurewifi-5.png|300px]]&lt;br /&gt;
* You&#039;ll be prompted to enter your wifi SSID and wifi password. &#039;&#039;&#039;Note: Your device can only use a 2.4GHz network&#039;&#039;&#039;: it is not compatible with 5GHz WiFi.&lt;br /&gt;
* The badge will restart using the credentials you&#039;ve provided and it will shut down its wifi access point. &lt;br /&gt;
   [[File:configurewifi-4.png|300px]]&lt;br /&gt;
* Your phone/computer will go back to using its usual wifi network and badge is now online!&lt;br /&gt;
&lt;br /&gt;
Note: If you are using an Android device to link the badge to your WiFi, it will pop up a dialog to say you are switching to a network that doesn&#039;t have Internet access and ask if you want to switch back. Select &amp;quot;Keep&amp;quot; to stay on the badge&#039;s temporary access point.&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - commandline with mpfshell ===&lt;br /&gt;
&lt;br /&gt;
If the above guide to setting up via the wifi AP (access point) doesn&#039;t work, you can put a configuration file onto the badge. You&#039;ll need a Python environment to do so, which you&#039;ll need anyway if you plan on writing your own badge software applications.&lt;br /&gt;
&lt;br /&gt;
* Start by getting [[Swagbadge2021_UpdatingSoftware|a copy of the aiko firmware, and installing mpfshell]]&lt;br /&gt;
* &#039;&#039;Note: Your device can only talk to a 2.4GHz network: it is not compatible with 5GHz.&#039;&#039;&lt;br /&gt;
* Edit aiko_engine_mp/configuration/net.py and insert the details of your SSID and password.&lt;br /&gt;
* use mpfshell: &amp;lt;code&amp;gt;mpfshell -o COM3&amp;lt;/code&amp;gt; (substitute the com port/tty of your badge)&lt;br /&gt;
* &amp;lt;code&amp;gt;put configuration/net.py configuration/net.py&amp;lt;/code&amp;gt;&lt;br /&gt;
* fire up repl to view the console log &lt;br /&gt;
* You can now restart your device&lt;br /&gt;
* On bootup it should now talk to your network and you can see it on the console log.&lt;br /&gt;
&lt;br /&gt;
Your badge will display its connection status on the screens.&lt;br /&gt;
&lt;br /&gt;
= Running pre-installed applications =&lt;br /&gt;
&lt;br /&gt;
== Aiko&#039;s minimal Swagbadge application ==&lt;br /&gt;
At the moment the badge by default a basic &amp;quot;Swagbadge&amp;quot; application within the Aiko framework. This application&lt;br /&gt;
* has a thread to keep wifi running, &lt;br /&gt;
* has a thread to stay connected to (our Australian, private) mqtt server&lt;br /&gt;
* has a thread to display a rotating header across the two oleds.&lt;br /&gt;
&lt;br /&gt;
You can now talk to your badge [[Swagbadge2021_MQTT|using MQTT messages]].&lt;br /&gt;
&lt;br /&gt;
== Running other applications ==&lt;br /&gt;
At the moment, &amp;quot;swagbadge&amp;quot; is the only application that&#039;s for use with the badge. &lt;br /&gt;
&lt;br /&gt;
There are [https://github.com/geekscape/aiko_engine_mp/tree/master/applications other applications] in the repo which are for other places the Aiko framework has been used.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve written an application of your own and want to run that by default on badge startup, &lt;br /&gt;
# edit your local copy of configuration/main.py and change the value of the &amp;quot;application&amp;quot; to point to your new application.&lt;br /&gt;
# using mpfshell, &#039;put&#039; configuration/main.py and applications/your_application.py onto the badge&lt;br /&gt;
# Restart the badge&lt;br /&gt;
&lt;br /&gt;
== Running example code ==&lt;br /&gt;
There is [https://github.com/geekscape/aiko_engine_mp/tree/master/examples example code] which has a number of examples in it, including a snake game and a demo of how to use various badge functions.&lt;br /&gt;
&lt;br /&gt;
# From your commandline on your computer, use mpfshell to put whatever example code you want onto the badge.&lt;br /&gt;
# To run example code, you can use the &amp;quot;emergency stop&amp;quot; function to halt any other applications and put you in the repl.&lt;br /&gt;
## Touch both of the bottom spots on the sliders&lt;br /&gt;
## Reboot the badge&lt;br /&gt;
# Now at the repl prompt, type (replace the name of the module as appropriate for the code you want to run): &lt;br /&gt;
&lt;br /&gt;
Use examples.game_snake as example:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
from examples.game_snake import run&lt;br /&gt;
run()&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ctrl-c to halt operation and return to the repl prompt.&lt;br /&gt;
&lt;br /&gt;
= Hardware pinout =&lt;br /&gt;
&lt;br /&gt;
You can get the schematic and pin mapping on this page: https://github.com/CCHS-Melbourne/Swag-Badge/blob/master/swag-badge-schematic.pdf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- GPIO0 : left breakout pin4 (can be VSPI CS/SS#1 if 2 SPI devices, otherwise wire CS to GND)&lt;br /&gt;
- GPIO2 : left breakout pin3 (can be VSPI CS/SS#2 if 2 SPI devices, otherwise wire CS to GND)&lt;br /&gt;
&lt;br /&gt;
- GPIO4 : SCL (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO5 : SDA (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO12/15: slider #1&lt;br /&gt;
- GPIO13: left breakout pin3 (can be used for TFT backlight)&lt;br /&gt;
- GPIO14/27: slider #2&lt;br /&gt;
- GPIO16: left switch  (under screen #1)&lt;br /&gt;
- GPIO17: right switch (under screen #2)&lt;br /&gt;
&lt;br /&gt;
- GPIO18: SAO3 pin3 + LB pin7  (also VSPI SCL/SCK/CLK/D0)&lt;br /&gt;
- GPIO23: SAO3 pin4            (also VSPI SDA/SDI/MOSI/D1)&lt;br /&gt;
&lt;br /&gt;
- GPIO19: SAO1 pin4&lt;br /&gt;
- GPIO22: SAO1 pin3 (also onboard blue LED in the back)&lt;br /&gt;
&lt;br /&gt;
- GPIO21: unused but not wired on this chip&lt;br /&gt;
&lt;br /&gt;
- GPIO25: SAO4 pin4 + RB pin6  (also VSPI DC/A0/RS)&lt;br /&gt;
- GPIO26: SAO4 pin3 + RB pin7  (also VSPI RES/RST)&lt;br /&gt;
&lt;br /&gt;
- GPIO32: SAO2 pin3 + RB pin4 (touch pin, can be used with SAO tux foot or nose touchpad) &lt;br /&gt;
- GPIO33: SAO2 pin4 + RB pin5 (touch pin, can be used with SAO tux foot or nose touchpad)&lt;br /&gt;
&lt;br /&gt;
- GPIO34: right breakout pin2 (input only)&lt;br /&gt;
- GPIO35: right breakout pin3 (input only)&lt;br /&gt;
&lt;br /&gt;
- GPIO36: unused but not wired on this chip (input only)&lt;br /&gt;
- GPIO39: unused but not wired on this chip (input only)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Hardware SPI for a device like SSD1331 ==&lt;br /&gt;
ESP32 has 2 DMA capable hardware SPI busses usable by the user: SPI2/HSPI and SPI3/VSPI (see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/spi_master.html and https://github.com/espressif/arduino-esp32/blob/master/libraries/SPI/examples/SPI_Multiple_Buses/SPI_Multiple_Buses.ino for how to use them at the same time ). The important note in the espressif doc is that if you do not use the dedicated default HWSPI pins, they get routed through a hardware MUX and your maximum SPI speed is lowered from 80Mhz to 40Mhz.&lt;br /&gt;
&lt;br /&gt;
If you would like to connect an SPI device like an SSD1331 96x64 color TFT, here are default hardware pin numbers, and pins you can use for non SPI signals (RES/RST, DC/A0/RS, and CS/SS):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  SD1331 Pin	        ESP32	ESP32&lt;br /&gt;
1 GND                   VSPI    HSPI &lt;br /&gt;
2 VCC&lt;br /&gt;
3 SCL/SCK/CLK/D0	18	14   &lt;br /&gt;
4 SDA/SDI/MOSI/D1	23	13   &lt;br /&gt;
---- 2 pins above and MISO are HWSPI, pins below are anything&lt;br /&gt;
---- RST is not part of SPI, it&#039;s an out of band signal to reset a TFT&lt;br /&gt;
---- This could be wired to the ESP32 EN(reset) pin&lt;br /&gt;
5 RES/RST		26	26   &lt;br /&gt;
---- Data/Command pin is not part of SPI but used to tell the TFT if incoming SPI&lt;br /&gt;
---- data is actually a command, or pixel data.&lt;br /&gt;
6 DC/A0/RS (data)	25	25   &lt;br /&gt;
---- Cable select chooses which SPI device we&#039;re talking to, if there is only&lt;br /&gt;
---- one, it can be tied to ground. Any pin is fine&lt;br /&gt;
7 CS/SS =&amp;gt; GND	        0	2   &lt;br /&gt;
&lt;br /&gt;
---- MISO is not used to talk to TFTs, and is a hardware pin, but unused here&lt;br /&gt;
  MISO		        19	12    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
pins 12/13/14 are already used by the badge, but 18/19/23 are usable (SAO3 and SAO1), and since MISO is unused, you could also assign it to GPIO21 which isn&#039;t wired at all on the lolin lite chip.  &lt;br /&gt;
If you&#039;d also like to keep SAO4 usable (25/26), you can wire CS/SS to ground to free up pin 27, move DC/AO/RS to pin 27, and free up pin 26 (RST) by wiring RST to the ESP32 ENA pin, which should issue a TFT reset every time the ESP32 is reset.&lt;br /&gt;
&lt;br /&gt;
End result: https://youtu.be/TYItVAa4tJY&lt;br /&gt;
&lt;br /&gt;
= Extensions: Adding a SAO =&lt;br /&gt;
* provided by others: look at [https://www.tindie.com/search/?q=SAO Tindie]&lt;br /&gt;
* [[Swagbadge2021_SAO|Build your own]]&lt;br /&gt;
&lt;br /&gt;
= Extensions: Writing your own applications =&lt;br /&gt;
&lt;br /&gt;
Between when we ship the board and when it arrives, there might be some changes to the software framework (Aiko). Here&#039;s how to update it. Or perhaps you&#039;re interested in writing your own applications? &lt;br /&gt;
&lt;br /&gt;
* [[Swagbadge2021_UpdatingSoftware|Updating the Software]]&lt;br /&gt;
* [[Swagbadge2021_SoftwareDev|Writing your own badge programs]]&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1374</id>
		<title>Swagbadge2021 GettingStarted</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1374"/>
		<updated>2021-02-13T02:45:27Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Hardware pinout */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Getting started with the Swagbadge =&lt;br /&gt;
&lt;br /&gt;
== Support ==&lt;br /&gt;
* The [https://spectrum.chat/lca2021-swagbadge Swag Badge Spectrum chat] is a place where the badge team hangs out, ready to answer your questions.&lt;br /&gt;
&lt;br /&gt;
== My package arrived in the mail, first steps. ==&lt;br /&gt;
* Your package should contain your badge, and some other goodies! &lt;br /&gt;
** [[File:swagbadgepackage.jpg|400px|alt=Image showing the contents of the swagbag package]]&lt;br /&gt;
** Badge&lt;br /&gt;
** SAO headers (x 4)&lt;br /&gt;
** SAO proto boards (x 2)&lt;br /&gt;
** SAO tux board&lt;br /&gt;
** Lanyard&lt;br /&gt;
** Stickers&lt;br /&gt;
** Instructions&lt;br /&gt;
* Take off the protective cases to reveal the screens.&lt;br /&gt;
* Powering it up&lt;br /&gt;
** Insert a micro USB cable into the badge and connect the other end to a USB port on your computer or USB power source.&lt;br /&gt;
** A green light should glow on the rear of the board, and a title appear across the two screens.&lt;br /&gt;
* Turning it on and off again&lt;br /&gt;
** Plugging/unplugging it is fine. Usually the badge isn&#039;t running anything intensely enough that just unpowering it would cause a problem.&lt;br /&gt;
* On bootup, you should see:&lt;br /&gt;
** The OLED screens will display &amp;quot;Aiko&amp;quot; and a version number as a title&lt;br /&gt;
** It will also display something else to tell you to set up your wifi.&lt;br /&gt;
&lt;br /&gt;
== Getting it on your network ==&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - wireless ===&lt;br /&gt;
&lt;br /&gt;
The first time you boot your badge, it won&#039;t know how to talk to your wifi network, so it creates its own temporary wifi network for you to connect to, so you can configure it.&lt;br /&gt;
&lt;br /&gt;
* Start your badge by plugging it in.&lt;br /&gt;
* The screens on your badge will say &amp;lt;code&amp;gt;Configure WiFi:&amp;lt;/code&amp;gt; &lt;br /&gt;
   [[File:configurewifi-1.png|300px]]&lt;br /&gt;
* Use your phone (or computer) to change wifi networks to use the badge. The badge wifi name starts with &amp;lt;code&amp;gt;aiko&amp;lt;/code&amp;gt; followed by some numbers/letters. &lt;br /&gt;
   [[File:configurewifi-2.png|200px]] -&amp;gt; [[File:configurewifi-3.png|200px]]&lt;br /&gt;
* Once you&#039;re connected to the badge wifi, open a web browser on that device to the IP address shown on the screens. Something like &amp;lt;code&amp;gt;http://192.168.4.1&amp;lt;/code&amp;gt; &lt;br /&gt;
   [[File:configurewifi-5.png|300px]]&lt;br /&gt;
* You&#039;ll be prompted to enter your wifi SSID and wifi password. &#039;&#039;&#039;Note: Your device can only use a 2.4GHz network&#039;&#039;&#039;: it is not compatible with 5GHz WiFi.&lt;br /&gt;
* The badge will restart using the credentials you&#039;ve provided and it will shut down its wifi access point. &lt;br /&gt;
   [[File:configurewifi-4.png|300px]]&lt;br /&gt;
* Your phone/computer will go back to using its usual wifi network and badge is now online!&lt;br /&gt;
&lt;br /&gt;
Note: If you are using an Android device to link the badge to your WiFi, it will pop up a dialog to say you are switching to a network that doesn&#039;t have Internet access and ask if you want to switch back. Select &amp;quot;Keep&amp;quot; to stay on the badge&#039;s temporary access point.&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - commandline with mpfshell ===&lt;br /&gt;
&lt;br /&gt;
If the above guide to setting up via the wifi AP (access point) doesn&#039;t work, you can put a configuration file onto the badge. You&#039;ll need a Python environment to do so, which you&#039;ll need anyway if you plan on writing your own badge software applications.&lt;br /&gt;
&lt;br /&gt;
* Start by getting [[Swagbadge2021_UpdatingSoftware|a copy of the aiko firmware, and installing mpfshell]]&lt;br /&gt;
* &#039;&#039;Note: Your device can only talk to a 2.4GHz network: it is not compatible with 5GHz.&#039;&#039;&lt;br /&gt;
* Edit aiko_engine_mp/configuration/net.py and insert the details of your SSID and password.&lt;br /&gt;
* use mpfshell: &amp;lt;code&amp;gt;mpfshell -o COM3&amp;lt;/code&amp;gt; (substitute the com port/tty of your badge)&lt;br /&gt;
* &amp;lt;code&amp;gt;put configuration/net.py configuration/net.py&amp;lt;/code&amp;gt;&lt;br /&gt;
* fire up repl to view the console log &lt;br /&gt;
* You can now restart your device&lt;br /&gt;
* On bootup it should now talk to your network and you can see it on the console log.&lt;br /&gt;
&lt;br /&gt;
Your badge will display its connection status on the screens.&lt;br /&gt;
&lt;br /&gt;
= Running pre-installed applications =&lt;br /&gt;
&lt;br /&gt;
== Aiko&#039;s minimal Swagbadge application ==&lt;br /&gt;
At the moment the badge by default a basic &amp;quot;Swagbadge&amp;quot; application within the Aiko framework. This application&lt;br /&gt;
* has a thread to keep wifi running, &lt;br /&gt;
* has a thread to stay connected to (our Australian, private) mqtt server&lt;br /&gt;
* has a thread to display a rotating header across the two oleds.&lt;br /&gt;
&lt;br /&gt;
You can now talk to your badge [[Swagbadge2021_MQTT|using MQTT messages]].&lt;br /&gt;
&lt;br /&gt;
== Running other applications ==&lt;br /&gt;
At the moment, &amp;quot;swagbadge&amp;quot; is the only application that&#039;s for use with the badge. &lt;br /&gt;
&lt;br /&gt;
There are [https://github.com/geekscape/aiko_engine_mp/tree/master/applications other applications] in the repo which are for other places the Aiko framework has been used.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve written an application of your own and want to run that by default on badge startup, &lt;br /&gt;
# edit your local copy of configuration/main.py and change the value of the &amp;quot;application&amp;quot; to point to your new application.&lt;br /&gt;
# using mpfshell, &#039;put&#039; configuration/main.py and applications/your_application.py onto the badge&lt;br /&gt;
# Restart the badge&lt;br /&gt;
&lt;br /&gt;
== Running example code ==&lt;br /&gt;
There is [https://github.com/geekscape/aiko_engine_mp/tree/master/examples example code] which has a number of examples in it, including a snake game and a demo of how to use various badge functions.&lt;br /&gt;
&lt;br /&gt;
# From your commandline on your computer, use mpfshell to put whatever example code you want onto the badge.&lt;br /&gt;
# To run example code, you can use the &amp;quot;emergency stop&amp;quot; function to halt any other applications and put you in the repl.&lt;br /&gt;
## Touch both of the bottom spots on the sliders&lt;br /&gt;
## Reboot the badge&lt;br /&gt;
# Now at the repl prompt, type (replace the name of the module as appropriate for the code you want to run): &lt;br /&gt;
&lt;br /&gt;
Use examples.game_snake as example:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
from examples.game_snake import run&lt;br /&gt;
run()&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ctrl-c to halt operation and return to the repl prompt.&lt;br /&gt;
&lt;br /&gt;
= Hardware pinout =&lt;br /&gt;
&lt;br /&gt;
You can get the schematic and pin mapping on this page: https://github.com/CCHS-Melbourne/Swag-Badge/blob/master/swag-badge-schematic.pdf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- GPIO0 : left breakout pin4 (can be VSPI CS/SS#1 if 2 SPI devices, otherwise wire CS to GND)&lt;br /&gt;
- GPIO2 : left breakout pin3 (can be VSPI CS/SS#2 if 2 SPI devices, otherwise wire CS to GND)&lt;br /&gt;
&lt;br /&gt;
- GPIO4 : SCL (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO5 : SDA (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO12/15: slider #1&lt;br /&gt;
- GPIO13: left breakout pin3 (can be used for TFT backlight)&lt;br /&gt;
- GPIO14/27: slider #2&lt;br /&gt;
- GPIO16: left switch  (under screen #1)&lt;br /&gt;
- GPIO17: right switch (under screen #2)&lt;br /&gt;
&lt;br /&gt;
- GPIO18: SAO3 pin3 + LB pin7  (also VSPI SCL/SCK/CLK/D0)&lt;br /&gt;
- GPIO23: SAO3 pin4            (also VSPI SDA/SDI/MOSI/D1)&lt;br /&gt;
&lt;br /&gt;
- GPIO19: SAO1 pin4&lt;br /&gt;
- GPIO22: SAO1 pin3 (also onboard blue LED in the back)&lt;br /&gt;
&lt;br /&gt;
- GPIO21: unused but not wired on this chip&lt;br /&gt;
&lt;br /&gt;
- GPIO25: SAO4 pin4 + RB pin6  (also VSPI DC/A0/RS)&lt;br /&gt;
- GPIO26: SAO4 pin3 + RB pin7  (also VSPI RES/RST)&lt;br /&gt;
&lt;br /&gt;
- GPIO32: SAO2 pin3 + RB pin4 (touch pin, can be used with SAO tux foot or nose touchpad) &lt;br /&gt;
- GPIO33: SAO2 pin4 + RB pin5 (touch pin, can be used with SAO tux foot or nose touchpad)&lt;br /&gt;
&lt;br /&gt;
- GPIO34: right breakout pin2 (input only)&lt;br /&gt;
- GPIO35: right breakout pin3 (input only)&lt;br /&gt;
&lt;br /&gt;
- GPIO36: unused but not wired on this chip (input only)&lt;br /&gt;
- GPIO39: unused but not wired on this chip (input only)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Hardware SPI for a device like SSD1331 ==&lt;br /&gt;
ESP32 has 2 DMA capable hardware SPI busses usable by the user: SPI2/HSPI and SPI3/VSPI (see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/spi_master.html and https://github.com/espressif/arduino-esp32/blob/master/libraries/SPI/examples/SPI_Multiple_Buses/SPI_Multiple_Buses.ino for how to use them at the same time ). The important note in the espressif doc is that if you do not use the dedicated default HWSPI pins, they get routed through a hardware MUX and your maximum SPI speed is lowered from 80Mhz to 40Mhz.&lt;br /&gt;
&lt;br /&gt;
If you would like to connect an SPI device like an SSD1331 96x64 color TFT, here are default hardware pin numbers, and pins you can use for non SPI signals (RES/RST, DC/A0/RS, and CS/SS):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  SD1331 Pin	        ESP32	ESP32&lt;br /&gt;
1 GND                   VSPI    HSPI &lt;br /&gt;
2 VCC&lt;br /&gt;
3 SCL/SCK/CLK/D0	18	14   &lt;br /&gt;
4 SDA/SDI/MOSI/D1	23	13   &lt;br /&gt;
---- 2 pins above and MISO are HWSPI, pins below are anything&lt;br /&gt;
---- RST is not part of SPI, it&#039;s an out of band signal to reset a TFT&lt;br /&gt;
---- This could be wired to the ESP32 EN(reset) pin&lt;br /&gt;
5 RES/RST		26	26   &lt;br /&gt;
---- Data/Command pin is not part of SPI but used to tell the TFT if incoming SPI&lt;br /&gt;
---- data is actually a command, or pixel data.&lt;br /&gt;
6 DC/A0/RS (data)	25	25   &lt;br /&gt;
---- Cable select chooses which SPI device we&#039;re talking to, if there is only&lt;br /&gt;
---- one, it can be tied to ground. Any pin is fine&lt;br /&gt;
7 CS/SS =&amp;gt; GND	        27	15   &lt;br /&gt;
&lt;br /&gt;
---- MISO is not used to talk to TFTs, and is a hardware pin, but unused here&lt;br /&gt;
  MISO		        19	12    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
pins 12/13/14 are already used by the badge, but 18/19/23 are usable (SAO3 and SAO1), and since MISO is unused, you could also assign it to GPIO21 which isn&#039;t wired at all on the lolin lite chip.  &lt;br /&gt;
If you&#039;d also like to keep SAO4 usable (25/26), you can wire CS/SS to ground to free up pin 27, move DC/AO/RS to pin 27, and free up pin 26 (RST) by wiring RST to the ESP32 ENA pin, which should issue a TFT reset every time the ESP32 is reset.&lt;br /&gt;
&lt;br /&gt;
End result: https://youtu.be/TYItVAa4tJY&lt;br /&gt;
&lt;br /&gt;
= Extensions: Adding a SAO =&lt;br /&gt;
* provided by others: look at [https://www.tindie.com/search/?q=SAO Tindie]&lt;br /&gt;
* [[Swagbadge2021_SAO|Build your own]]&lt;br /&gt;
&lt;br /&gt;
= Extensions: Writing your own applications =&lt;br /&gt;
&lt;br /&gt;
Between when we ship the board and when it arrives, there might be some changes to the software framework (Aiko). Here&#039;s how to update it. Or perhaps you&#039;re interested in writing your own applications? &lt;br /&gt;
&lt;br /&gt;
* [[Swagbadge2021_UpdatingSoftware|Updating the Software]]&lt;br /&gt;
* [[Swagbadge2021_SoftwareDev|Writing your own badge programs]]&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1373</id>
		<title>Swagbadge2021 GettingStarted</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1373"/>
		<updated>2021-02-13T02:44:35Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Hardware pinout */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Getting started with the Swagbadge =&lt;br /&gt;
&lt;br /&gt;
== Support ==&lt;br /&gt;
* The [https://spectrum.chat/lca2021-swagbadge Swag Badge Spectrum chat] is a place where the badge team hangs out, ready to answer your questions.&lt;br /&gt;
&lt;br /&gt;
== My package arrived in the mail, first steps. ==&lt;br /&gt;
* Your package should contain your badge, and some other goodies! &lt;br /&gt;
** [[File:swagbadgepackage.jpg|400px|alt=Image showing the contents of the swagbag package]]&lt;br /&gt;
** Badge&lt;br /&gt;
** SAO headers (x 4)&lt;br /&gt;
** SAO proto boards (x 2)&lt;br /&gt;
** SAO tux board&lt;br /&gt;
** Lanyard&lt;br /&gt;
** Stickers&lt;br /&gt;
** Instructions&lt;br /&gt;
* Take off the protective cases to reveal the screens.&lt;br /&gt;
* Powering it up&lt;br /&gt;
** Insert a micro USB cable into the badge and connect the other end to a USB port on your computer or USB power source.&lt;br /&gt;
** A green light should glow on the rear of the board, and a title appear across the two screens.&lt;br /&gt;
* Turning it on and off again&lt;br /&gt;
** Plugging/unplugging it is fine. Usually the badge isn&#039;t running anything intensely enough that just unpowering it would cause a problem.&lt;br /&gt;
* On bootup, you should see:&lt;br /&gt;
** The OLED screens will display &amp;quot;Aiko&amp;quot; and a version number as a title&lt;br /&gt;
** It will also display something else to tell you to set up your wifi.&lt;br /&gt;
&lt;br /&gt;
== Getting it on your network ==&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - wireless ===&lt;br /&gt;
&lt;br /&gt;
The first time you boot your badge, it won&#039;t know how to talk to your wifi network, so it creates its own temporary wifi network for you to connect to, so you can configure it.&lt;br /&gt;
&lt;br /&gt;
* Start your badge by plugging it in.&lt;br /&gt;
* The screens on your badge will say &amp;lt;code&amp;gt;Configure WiFi:&amp;lt;/code&amp;gt; &lt;br /&gt;
   [[File:configurewifi-1.png|300px]]&lt;br /&gt;
* Use your phone (or computer) to change wifi networks to use the badge. The badge wifi name starts with &amp;lt;code&amp;gt;aiko&amp;lt;/code&amp;gt; followed by some numbers/letters. &lt;br /&gt;
   [[File:configurewifi-2.png|200px]] -&amp;gt; [[File:configurewifi-3.png|200px]]&lt;br /&gt;
* Once you&#039;re connected to the badge wifi, open a web browser on that device to the IP address shown on the screens. Something like &amp;lt;code&amp;gt;http://192.168.4.1&amp;lt;/code&amp;gt; &lt;br /&gt;
   [[File:configurewifi-5.png|300px]]&lt;br /&gt;
* You&#039;ll be prompted to enter your wifi SSID and wifi password. &#039;&#039;&#039;Note: Your device can only use a 2.4GHz network&#039;&#039;&#039;: it is not compatible with 5GHz WiFi.&lt;br /&gt;
* The badge will restart using the credentials you&#039;ve provided and it will shut down its wifi access point. &lt;br /&gt;
   [[File:configurewifi-4.png|300px]]&lt;br /&gt;
* Your phone/computer will go back to using its usual wifi network and badge is now online!&lt;br /&gt;
&lt;br /&gt;
Note: If you are using an Android device to link the badge to your WiFi, it will pop up a dialog to say you are switching to a network that doesn&#039;t have Internet access and ask if you want to switch back. Select &amp;quot;Keep&amp;quot; to stay on the badge&#039;s temporary access point.&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - commandline with mpfshell ===&lt;br /&gt;
&lt;br /&gt;
If the above guide to setting up via the wifi AP (access point) doesn&#039;t work, you can put a configuration file onto the badge. You&#039;ll need a Python environment to do so, which you&#039;ll need anyway if you plan on writing your own badge software applications.&lt;br /&gt;
&lt;br /&gt;
* Start by getting [[Swagbadge2021_UpdatingSoftware|a copy of the aiko firmware, and installing mpfshell]]&lt;br /&gt;
* &#039;&#039;Note: Your device can only talk to a 2.4GHz network: it is not compatible with 5GHz.&#039;&#039;&lt;br /&gt;
* Edit aiko_engine_mp/configuration/net.py and insert the details of your SSID and password.&lt;br /&gt;
* use mpfshell: &amp;lt;code&amp;gt;mpfshell -o COM3&amp;lt;/code&amp;gt; (substitute the com port/tty of your badge)&lt;br /&gt;
* &amp;lt;code&amp;gt;put configuration/net.py configuration/net.py&amp;lt;/code&amp;gt;&lt;br /&gt;
* fire up repl to view the console log &lt;br /&gt;
* You can now restart your device&lt;br /&gt;
* On bootup it should now talk to your network and you can see it on the console log.&lt;br /&gt;
&lt;br /&gt;
Your badge will display its connection status on the screens.&lt;br /&gt;
&lt;br /&gt;
= Running pre-installed applications =&lt;br /&gt;
&lt;br /&gt;
== Aiko&#039;s minimal Swagbadge application ==&lt;br /&gt;
At the moment the badge by default a basic &amp;quot;Swagbadge&amp;quot; application within the Aiko framework. This application&lt;br /&gt;
* has a thread to keep wifi running, &lt;br /&gt;
* has a thread to stay connected to (our Australian, private) mqtt server&lt;br /&gt;
* has a thread to display a rotating header across the two oleds.&lt;br /&gt;
&lt;br /&gt;
You can now talk to your badge [[Swagbadge2021_MQTT|using MQTT messages]].&lt;br /&gt;
&lt;br /&gt;
== Running other applications ==&lt;br /&gt;
At the moment, &amp;quot;swagbadge&amp;quot; is the only application that&#039;s for use with the badge. &lt;br /&gt;
&lt;br /&gt;
There are [https://github.com/geekscape/aiko_engine_mp/tree/master/applications other applications] in the repo which are for other places the Aiko framework has been used.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve written an application of your own and want to run that by default on badge startup, &lt;br /&gt;
# edit your local copy of configuration/main.py and change the value of the &amp;quot;application&amp;quot; to point to your new application.&lt;br /&gt;
# using mpfshell, &#039;put&#039; configuration/main.py and applications/your_application.py onto the badge&lt;br /&gt;
# Restart the badge&lt;br /&gt;
&lt;br /&gt;
== Running example code ==&lt;br /&gt;
There is [https://github.com/geekscape/aiko_engine_mp/tree/master/examples example code] which has a number of examples in it, including a snake game and a demo of how to use various badge functions.&lt;br /&gt;
&lt;br /&gt;
# From your commandline on your computer, use mpfshell to put whatever example code you want onto the badge.&lt;br /&gt;
# To run example code, you can use the &amp;quot;emergency stop&amp;quot; function to halt any other applications and put you in the repl.&lt;br /&gt;
## Touch both of the bottom spots on the sliders&lt;br /&gt;
## Reboot the badge&lt;br /&gt;
# Now at the repl prompt, type (replace the name of the module as appropriate for the code you want to run): &lt;br /&gt;
&lt;br /&gt;
Use examples.game_snake as example:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
from examples.game_snake import run&lt;br /&gt;
run()&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ctrl-c to halt operation and return to the repl prompt.&lt;br /&gt;
&lt;br /&gt;
= Hardware pinout =&lt;br /&gt;
&lt;br /&gt;
You can get the schematic and pin mapping on this page: https://github.com/CCHS-Melbourne/Swag-Badge/blob/master/swag-badge-schematic.pdf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- GPIO0 : left breakout pin4 (can be used as VSPI CS/SS#1 if 2 SPI devices, otherwise CS can be wired to GND)&lt;br /&gt;
- GPIO2 : left breakout pin3 (can be used as VSPI CS/SS#2 if 2 SPI devices, otherwise CS can be wired to GND)&lt;br /&gt;
&lt;br /&gt;
- GPIO4 : SCL (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO5 : SDA (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO12/15: slider #1&lt;br /&gt;
- GPIO13: left breakout pin3 (can be used for TFT backlight)&lt;br /&gt;
- GPIO14/27: slider #2&lt;br /&gt;
- GPIO16: left switch  (under screen #1)&lt;br /&gt;
- GPIO17: right switch (under screen #2)&lt;br /&gt;
&lt;br /&gt;
- GPIO18: SAO3 pin3 + LB pin7  (also VSPI SCL/SCK/CLK/D0)&lt;br /&gt;
- GPIO23: SAO3 pin4            (also VSPI SDA/SDI/MOSI/D1)&lt;br /&gt;
&lt;br /&gt;
- GPIO19: SAO1 pin4&lt;br /&gt;
- GPIO22: SAO1 pin3 (also onboard blue LED in the back)&lt;br /&gt;
&lt;br /&gt;
- GPIO21: unused but not wired on this chip&lt;br /&gt;
&lt;br /&gt;
- GPIO25: SAO4 pin4 + RB pin6  (also VSPI DC/A0/RS)&lt;br /&gt;
- GPIO26: SAO4 pin3 + RB pin7  (also VSPI RES/RST)&lt;br /&gt;
&lt;br /&gt;
- GPIO32: SAO2 pin3 + RB pin4 (touch pin, can be used with SAO tux foot or nose touchpad) &lt;br /&gt;
- GPIO33: SAO2 pin4 + RB pin5 (touch pin, can be used with SAO tux foot or nose touchpad)&lt;br /&gt;
&lt;br /&gt;
- GPIO34: right breakout pin2 (input only)&lt;br /&gt;
- GPIO35: right breakout pin3 (input only)&lt;br /&gt;
&lt;br /&gt;
- GPIO36: unused but not wired on this chip (input only)&lt;br /&gt;
- GPIO39: unused but not wired on this chip (input only)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Hardware SPI for a device like SSD1331 ==&lt;br /&gt;
ESP32 has 2 DMA capable hardware SPI busses usable by the user: SPI2/HSPI and SPI3/VSPI (see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/spi_master.html and https://github.com/espressif/arduino-esp32/blob/master/libraries/SPI/examples/SPI_Multiple_Buses/SPI_Multiple_Buses.ino for how to use them at the same time ). The important note in the espressif doc is that if you do not use the dedicated default HWSPI pins, they get routed through a hardware MUX and your maximum SPI speed is lowered from 80Mhz to 40Mhz.&lt;br /&gt;
&lt;br /&gt;
If you would like to connect an SPI device like an SSD1331 96x64 color TFT, here are default hardware pin numbers, and pins you can use for non SPI signals (RES/RST, DC/A0/RS, and CS/SS):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  SD1331 Pin	        ESP32	ESP32&lt;br /&gt;
1 GND                   VSPI    HSPI &lt;br /&gt;
2 VCC&lt;br /&gt;
3 SCL/SCK/CLK/D0	18	14   &lt;br /&gt;
4 SDA/SDI/MOSI/D1	23	13   &lt;br /&gt;
---- 2 pins above and MISO are HWSPI, pins below are anything&lt;br /&gt;
---- RST is not part of SPI, it&#039;s an out of band signal to reset a TFT&lt;br /&gt;
---- This could be wired to the ESP32 EN(reset) pin&lt;br /&gt;
5 RES/RST		26	26   &lt;br /&gt;
---- Data/Command pin is not part of SPI but used to tell the TFT if incoming SPI&lt;br /&gt;
---- data is actually a command, or pixel data.&lt;br /&gt;
6 DC/A0/RS (data)	25	25   &lt;br /&gt;
---- Cable select chooses which SPI device we&#039;re talking to, if there is only&lt;br /&gt;
---- one, it can be tied to ground. Any pin is fine&lt;br /&gt;
7 CS/SS =&amp;gt; GND	        27	15   &lt;br /&gt;
&lt;br /&gt;
---- MISO is not used to talk to TFTs, and is a hardware pin, but unused here&lt;br /&gt;
  MISO		        19	12    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
pins 12/13/14 are already used by the badge, but 18/19/23 are usable (SAO3 and SAO1), and since MISO is unused, you could also assign it to GPIO21 which isn&#039;t wired at all on the lolin lite chip.  &lt;br /&gt;
If you&#039;d also like to keep SAO4 usable (25/26), you can wire CS/SS to ground to free up pin 27, move DC/AO/RS to pin 27, and free up pin 26 (RST) by wiring RST to the ESP32 ENA pin, which should issue a TFT reset every time the ESP32 is reset.&lt;br /&gt;
&lt;br /&gt;
End result: https://youtu.be/TYItVAa4tJY&lt;br /&gt;
&lt;br /&gt;
= Extensions: Adding a SAO =&lt;br /&gt;
* provided by others: look at [https://www.tindie.com/search/?q=SAO Tindie]&lt;br /&gt;
* [[Swagbadge2021_SAO|Build your own]]&lt;br /&gt;
&lt;br /&gt;
= Extensions: Writing your own applications =&lt;br /&gt;
&lt;br /&gt;
Between when we ship the board and when it arrives, there might be some changes to the software framework (Aiko). Here&#039;s how to update it. Or perhaps you&#039;re interested in writing your own applications? &lt;br /&gt;
&lt;br /&gt;
* [[Swagbadge2021_UpdatingSoftware|Updating the Software]]&lt;br /&gt;
* [[Swagbadge2021_SoftwareDev|Writing your own badge programs]]&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1372</id>
		<title>Swagbadge2021 GettingStarted</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1372"/>
		<updated>2021-02-08T05:37:35Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Hardware pinout */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Getting started with the Swagbadge =&lt;br /&gt;
&lt;br /&gt;
== Support ==&lt;br /&gt;
* The [https://spectrum.chat/lca2021-swagbadge Swag Badge Spectrum chat] is a place where the badge team hangs out, ready to answer your questions.&lt;br /&gt;
&lt;br /&gt;
== My package arrived in the mail, first steps. ==&lt;br /&gt;
* Your package should contain your badge, and some other goodies! &lt;br /&gt;
** [[File:swagbadgepackage.jpg|400px|alt=Image showing the contents of the swagbag package]]&lt;br /&gt;
** Badge&lt;br /&gt;
** SAO headers (x 4)&lt;br /&gt;
** SAO proto boards (x 2)&lt;br /&gt;
** SAO tux board&lt;br /&gt;
** Lanyard&lt;br /&gt;
** Stickers&lt;br /&gt;
** Instructions&lt;br /&gt;
* Take off the protective cases to reveal the screens.&lt;br /&gt;
* Powering it up&lt;br /&gt;
** Insert a micro USB cable into the badge and connect the other end to a USB port on your computer or USB power source.&lt;br /&gt;
** A green light should glow on the rear of the board, and a title appear across the two screens.&lt;br /&gt;
* Turning it on and off again&lt;br /&gt;
** Plugging/unplugging it is fine. Usually the badge isn&#039;t running anything intensely enough that just unpowering it would cause a problem.&lt;br /&gt;
* On bootup, you should see:&lt;br /&gt;
** The OLED screens will display &amp;quot;Aiko&amp;quot; and a version number as a title&lt;br /&gt;
** It will also display something else to tell you to set up your wifi.&lt;br /&gt;
&lt;br /&gt;
== Getting it on your network ==&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - wireless ===&lt;br /&gt;
&lt;br /&gt;
The first time you boot your badge, it won&#039;t know how to talk to your wifi network, so it creates its own temporary wifi network for you to connect to, so you can configure it.&lt;br /&gt;
&lt;br /&gt;
* Start your badge by plugging it in.&lt;br /&gt;
* The screens on your badge will say &amp;lt;code&amp;gt;Configure WiFi:&amp;lt;/code&amp;gt; &lt;br /&gt;
   [[File:configurewifi-1.png|300px]]&lt;br /&gt;
* Use your phone (or computer) to change wifi networks to use the badge. The badge wifi name starts with &amp;lt;code&amp;gt;aiko&amp;lt;/code&amp;gt; followed by some numbers/letters. &lt;br /&gt;
   [[File:configurewifi-2.png|200px]] -&amp;gt; [[File:configurewifi-3.png|200px]]&lt;br /&gt;
* Once you&#039;re connected to the badge wifi, open a web browser on that device to the IP address shown on the screens. Something like &amp;lt;code&amp;gt;http://192.168.4.1&amp;lt;/code&amp;gt; &lt;br /&gt;
   [[File:configurewifi-5.png|300px]]&lt;br /&gt;
* You&#039;ll be prompted to enter your wifi SSID and wifi password. &#039;&#039;&#039;Note: Your device can only use a 2.4GHz network&#039;&#039;&#039;: it is not compatible with 5GHz WiFi.&lt;br /&gt;
* The badge will restart using the credentials you&#039;ve provided and it will shut down its wifi access point. &lt;br /&gt;
   [[File:configurewifi-4.png|300px]]&lt;br /&gt;
* Your phone/computer will go back to using its usual wifi network and badge is now online!&lt;br /&gt;
&lt;br /&gt;
Note: If you are using an Android device to link the badge to your WiFi, it will pop up a dialog to say you are switching to a network that doesn&#039;t have Internet access and ask if you want to switch back. Select &amp;quot;Keep&amp;quot; to stay on the badge&#039;s temporary access point.&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - commandline with mpfshell ===&lt;br /&gt;
&lt;br /&gt;
If the above guide to setting up via the wifi AP (access point) doesn&#039;t work, you can put a configuration file onto the badge. You&#039;ll need a Python environment to do so, which you&#039;ll need anyway if you plan on writing your own badge software applications.&lt;br /&gt;
&lt;br /&gt;
* Start by getting [[Swagbadge2021_UpdatingSoftware|a copy of the aiko firmware, and installing mpfshell]]&lt;br /&gt;
* &#039;&#039;Note: Your device can only talk to a 2.4GHz network: it is not compatible with 5GHz.&#039;&#039;&lt;br /&gt;
* Edit aiko_engine_mp/configuration/net.py and insert the details of your SSID and password.&lt;br /&gt;
* use mpfshell: &amp;lt;code&amp;gt;mpfshell -o COM3&amp;lt;/code&amp;gt; (substitute the com port/tty of your badge)&lt;br /&gt;
* &amp;lt;code&amp;gt;put configuration/net.py configuration/net.py&amp;lt;/code&amp;gt;&lt;br /&gt;
* fire up repl to view the console log &lt;br /&gt;
* You can now restart your device&lt;br /&gt;
* On bootup it should now talk to your network and you can see it on the console log.&lt;br /&gt;
&lt;br /&gt;
Your badge will display its connection status on the screens.&lt;br /&gt;
&lt;br /&gt;
= Running pre-installed applications =&lt;br /&gt;
&lt;br /&gt;
== Aiko&#039;s minimal Swagbadge application ==&lt;br /&gt;
At the moment the badge by default a basic &amp;quot;Swagbadge&amp;quot; application within the Aiko framework. This application&lt;br /&gt;
* has a thread to keep wifi running, &lt;br /&gt;
* has a thread to stay connected to (our Australian, private) mqtt server&lt;br /&gt;
* has a thread to display a rotating header across the two oleds.&lt;br /&gt;
&lt;br /&gt;
You can now talk to your badge [[Swagbadge2021_MQTT|using MQTT messages]].&lt;br /&gt;
&lt;br /&gt;
== Running other applications ==&lt;br /&gt;
At the moment, &amp;quot;swagbadge&amp;quot; is the only application that&#039;s for use with the badge. &lt;br /&gt;
&lt;br /&gt;
There are [https://github.com/geekscape/aiko_engine_mp/tree/master/applications other applications] in the repo which are for other places the Aiko framework has been used.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve written an application of your own and want to run that by default on badge startup, &lt;br /&gt;
# edit your local copy of configuration/main.py and change the value of the &amp;quot;application&amp;quot; to point to your new application.&lt;br /&gt;
# using mpfshell, &#039;put&#039; configuration/main.py and applications/your_application.py onto the badge&lt;br /&gt;
# Restart the badge&lt;br /&gt;
&lt;br /&gt;
== Running example code ==&lt;br /&gt;
There is [https://github.com/geekscape/aiko_engine_mp/tree/master/examples example code] which has a number of examples in it, including a snake game and a demo of how to use various badge functions.&lt;br /&gt;
&lt;br /&gt;
# From your commandline on your computer, use mpfshell to put whatever example code you want onto the badge.&lt;br /&gt;
# To run example code, you can use the &amp;quot;emergency stop&amp;quot; function to halt any other applications and put you in the repl.&lt;br /&gt;
## Touch both of the bottom spots on the sliders&lt;br /&gt;
## Reboot the badge&lt;br /&gt;
# Now at the repl prompt, type (replace the name of the module as appropriate for the code you want to run): &lt;br /&gt;
&lt;br /&gt;
Use examples.game_snake as example:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
from examples.game_snake import run&lt;br /&gt;
run()&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ctrl-c to halt operation and return to the repl prompt.&lt;br /&gt;
&lt;br /&gt;
= Hardware pinout =&lt;br /&gt;
&lt;br /&gt;
You can get the schematic and pin mapping on this page: https://github.com/CCHS-Melbourne/Swag-Badge/blob/master/swag-badge-schematic.pdf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- GPIO0 : left breakout pin4&lt;br /&gt;
- GPIO2 : left breakout pin3&lt;br /&gt;
&lt;br /&gt;
- GPIO4 : SCL (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO5 : SDA (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO12/15: slider #1&lt;br /&gt;
- GPIO13: left breakout pin3&lt;br /&gt;
- GPIO14/27: slider #2 (can be used as VSPI CS/SS#2 and #1 of if one SPI device only, CS is wired to GND)&lt;br /&gt;
- GPIO16: left switch  (under screen #1)&lt;br /&gt;
- GPIO17: right switch (under screen #2)&lt;br /&gt;
&lt;br /&gt;
- GPIO18: SAO3 pin3 + LB pin7  (also VSPI SCL/SCK/CLK/D0)&lt;br /&gt;
- GPIO23: SAO3 pin4            (also VSPI SDA/SDI/MOSI/D1)&lt;br /&gt;
&lt;br /&gt;
- GPIO19: SAO1 pin4&lt;br /&gt;
- GPIO22: SAO1 pin3 (also onboard blue LED in the back)&lt;br /&gt;
&lt;br /&gt;
- GPIO21: unused but not wired on this chip&lt;br /&gt;
&lt;br /&gt;
- GPIO25: SAO4 pin4 + RB pin6  (also VSPI DC/A0/RS)&lt;br /&gt;
- GPIO26: SAO4 pin3 + RB pin7  (also VSPI RES/RST)&lt;br /&gt;
&lt;br /&gt;
- GPIO32: SAO2 pin3 + RB pin4 (touch pin, can be used with SAO tux foot or nose touchpad) &lt;br /&gt;
- GPIO33: SAO2 pin4 + RB pin5 (touch pin, can be used with SAO tux foot or nose touchpad)&lt;br /&gt;
&lt;br /&gt;
- GPIO34: right breakout pin2 (input only)&lt;br /&gt;
- GPIO35: right breakout pin3 (input only)&lt;br /&gt;
&lt;br /&gt;
- GPIO36: unused but not wired on this chip (input only)&lt;br /&gt;
- GPIO39: unused but not wired on this chip (input only)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Hardware SPI for a device like SSD1331 ==&lt;br /&gt;
ESP32 has 2 DMA capable hardware SPI busses usable by the user: SPI2/HSPI and SPI3/VSPI (see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/spi_master.html and https://github.com/espressif/arduino-esp32/blob/master/libraries/SPI/examples/SPI_Multiple_Buses/SPI_Multiple_Buses.ino for how to use them at the same time ). The important note in the espressif doc is that if you do not use the dedicated default HWSPI pins, they get routed through a hardware MUX and your maximum SPI speed is lowered from 80Mhz to 40Mhz.&lt;br /&gt;
&lt;br /&gt;
If you would like to connect an SPI device like an SSD1331 96x64 color TFT, here are default hardware pin numbers, and pins you can use for non SPI signals (RES/RST, DC/A0/RS, and CS/SS):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  SD1331 Pin	        ESP32	ESP32&lt;br /&gt;
1 GND                   VSPI    HSPI &lt;br /&gt;
2 VCC&lt;br /&gt;
3 SCL/SCK/CLK/D0	18	14   &lt;br /&gt;
4 SDA/SDI/MOSI/D1	23	13   &lt;br /&gt;
---- 2 pins above and MISO are HWSPI, pins below are anything&lt;br /&gt;
---- RST is not part of SPI, it&#039;s an out of band signal to reset a TFT&lt;br /&gt;
---- This could be wired to the ESP32 EN(reset) pin&lt;br /&gt;
5 RES/RST		26	26   &lt;br /&gt;
---- Data/Command pin is not part of SPI but used to tell the TFT if incoming SPI&lt;br /&gt;
---- data is actually a command, or pixel data.&lt;br /&gt;
6 DC/A0/RS (data)	25	25   &lt;br /&gt;
---- Cable select chooses which SPI device we&#039;re talking to, if there is only&lt;br /&gt;
---- one, it can be tied to ground. Any pin is fine&lt;br /&gt;
7 CS/SS =&amp;gt; GND	        27	15   &lt;br /&gt;
&lt;br /&gt;
---- MISO is not used to talk to TFTs, and is a hardware pin, but unused here&lt;br /&gt;
  MISO		        19	12    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
pins 12/13/14 are already used by the badge, but 18/19/23 are usable (SAO3 and SAO1), and since MISO is unused, you could also assign it to GPIO21 which isn&#039;t wired at all on the lolin lite chip.  &lt;br /&gt;
If you&#039;d also like to keep SAO4 usable (25/26), you can wire CS/SS to ground to free up pin 27, move DC/AO/RS to pin 27, and free up pin 26 (RST) by wiring RST to the ESP32 ENA pin, which should issue a TFT reset every time the ESP32 is reset.&lt;br /&gt;
&lt;br /&gt;
End result: https://youtu.be/TYItVAa4tJY&lt;br /&gt;
&lt;br /&gt;
= Extensions: Adding a SAO =&lt;br /&gt;
* provided by others: look at [https://www.tindie.com/search/?q=SAO Tindie]&lt;br /&gt;
* [[Swagbadge2021_SAO|Build your own]]&lt;br /&gt;
&lt;br /&gt;
= Extensions: Writing your own applications =&lt;br /&gt;
&lt;br /&gt;
Between when we ship the board and when it arrives, there might be some changes to the software framework (Aiko). Here&#039;s how to update it. Or perhaps you&#039;re interested in writing your own applications? &lt;br /&gt;
&lt;br /&gt;
* [[Swagbadge2021_UpdatingSoftware|Updating the Software]]&lt;br /&gt;
* [[Swagbadge2021_SoftwareDev|Writing your own badge programs]]&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1371</id>
		<title>Swagbadge2021 GettingStarted</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1371"/>
		<updated>2021-02-08T05:35:30Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Using Hardware SPI for a device like SSD1331 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Getting started with the Swagbadge =&lt;br /&gt;
&lt;br /&gt;
== Support ==&lt;br /&gt;
* The [https://spectrum.chat/lca2021-swagbadge Swag Badge Spectrum chat] is a place where the badge team hangs out, ready to answer your questions.&lt;br /&gt;
&lt;br /&gt;
== My package arrived in the mail, first steps. ==&lt;br /&gt;
* Your package should contain your badge, and some other goodies! &lt;br /&gt;
** [[File:swagbadgepackage.jpg|400px|alt=Image showing the contents of the swagbag package]]&lt;br /&gt;
** Badge&lt;br /&gt;
** SAO headers (x 4)&lt;br /&gt;
** SAO proto boards (x 2)&lt;br /&gt;
** SAO tux board&lt;br /&gt;
** Lanyard&lt;br /&gt;
** Stickers&lt;br /&gt;
** Instructions&lt;br /&gt;
* Take off the protective cases to reveal the screens.&lt;br /&gt;
* Powering it up&lt;br /&gt;
** Insert a micro USB cable into the badge and connect the other end to a USB port on your computer or USB power source.&lt;br /&gt;
** A green light should glow on the rear of the board, and a title appear across the two screens.&lt;br /&gt;
* Turning it on and off again&lt;br /&gt;
** Plugging/unplugging it is fine. Usually the badge isn&#039;t running anything intensely enough that just unpowering it would cause a problem.&lt;br /&gt;
* On bootup, you should see:&lt;br /&gt;
** The OLED screens will display &amp;quot;Aiko&amp;quot; and a version number as a title&lt;br /&gt;
** It will also display something else to tell you to set up your wifi.&lt;br /&gt;
&lt;br /&gt;
== Getting it on your network ==&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - wireless ===&lt;br /&gt;
&lt;br /&gt;
The first time you boot your badge, it won&#039;t know how to talk to your wifi network, so it creates its own temporary wifi network for you to connect to, so you can configure it.&lt;br /&gt;
&lt;br /&gt;
* Start your badge by plugging it in.&lt;br /&gt;
* The screens on your badge will say &amp;lt;code&amp;gt;Configure WiFi:&amp;lt;/code&amp;gt; &lt;br /&gt;
   [[File:configurewifi-1.png|300px]]&lt;br /&gt;
* Use your phone (or computer) to change wifi networks to use the badge. The badge wifi name starts with &amp;lt;code&amp;gt;aiko&amp;lt;/code&amp;gt; followed by some numbers/letters. &lt;br /&gt;
   [[File:configurewifi-2.png|200px]] -&amp;gt; [[File:configurewifi-3.png|200px]]&lt;br /&gt;
* Once you&#039;re connected to the badge wifi, open a web browser on that device to the IP address shown on the screens. Something like &amp;lt;code&amp;gt;http://192.168.4.1&amp;lt;/code&amp;gt; &lt;br /&gt;
   [[File:configurewifi-5.png|300px]]&lt;br /&gt;
* You&#039;ll be prompted to enter your wifi SSID and wifi password. &#039;&#039;&#039;Note: Your device can only use a 2.4GHz network&#039;&#039;&#039;: it is not compatible with 5GHz WiFi.&lt;br /&gt;
* The badge will restart using the credentials you&#039;ve provided and it will shut down its wifi access point. &lt;br /&gt;
   [[File:configurewifi-4.png|300px]]&lt;br /&gt;
* Your phone/computer will go back to using its usual wifi network and badge is now online!&lt;br /&gt;
&lt;br /&gt;
Note: If you are using an Android device to link the badge to your WiFi, it will pop up a dialog to say you are switching to a network that doesn&#039;t have Internet access and ask if you want to switch back. Select &amp;quot;Keep&amp;quot; to stay on the badge&#039;s temporary access point.&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - commandline with mpfshell ===&lt;br /&gt;
&lt;br /&gt;
If the above guide to setting up via the wifi AP (access point) doesn&#039;t work, you can put a configuration file onto the badge. You&#039;ll need a Python environment to do so, which you&#039;ll need anyway if you plan on writing your own badge software applications.&lt;br /&gt;
&lt;br /&gt;
* Start by getting [[Swagbadge2021_UpdatingSoftware|a copy of the aiko firmware, and installing mpfshell]]&lt;br /&gt;
* &#039;&#039;Note: Your device can only talk to a 2.4GHz network: it is not compatible with 5GHz.&#039;&#039;&lt;br /&gt;
* Edit aiko_engine_mp/configuration/net.py and insert the details of your SSID and password.&lt;br /&gt;
* use mpfshell: &amp;lt;code&amp;gt;mpfshell -o COM3&amp;lt;/code&amp;gt; (substitute the com port/tty of your badge)&lt;br /&gt;
* &amp;lt;code&amp;gt;put configuration/net.py configuration/net.py&amp;lt;/code&amp;gt;&lt;br /&gt;
* fire up repl to view the console log &lt;br /&gt;
* You can now restart your device&lt;br /&gt;
* On bootup it should now talk to your network and you can see it on the console log.&lt;br /&gt;
&lt;br /&gt;
Your badge will display its connection status on the screens.&lt;br /&gt;
&lt;br /&gt;
= Running pre-installed applications =&lt;br /&gt;
&lt;br /&gt;
== Aiko&#039;s minimal Swagbadge application ==&lt;br /&gt;
At the moment the badge by default a basic &amp;quot;Swagbadge&amp;quot; application within the Aiko framework. This application&lt;br /&gt;
* has a thread to keep wifi running, &lt;br /&gt;
* has a thread to stay connected to (our Australian, private) mqtt server&lt;br /&gt;
* has a thread to display a rotating header across the two oleds.&lt;br /&gt;
&lt;br /&gt;
You can now talk to your badge [[Swagbadge2021_MQTT|using MQTT messages]].&lt;br /&gt;
&lt;br /&gt;
== Running other applications ==&lt;br /&gt;
At the moment, &amp;quot;swagbadge&amp;quot; is the only application that&#039;s for use with the badge. &lt;br /&gt;
&lt;br /&gt;
There are [https://github.com/geekscape/aiko_engine_mp/tree/master/applications other applications] in the repo which are for other places the Aiko framework has been used.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve written an application of your own and want to run that by default on badge startup, &lt;br /&gt;
# edit your local copy of configuration/main.py and change the value of the &amp;quot;application&amp;quot; to point to your new application.&lt;br /&gt;
# using mpfshell, &#039;put&#039; configuration/main.py and applications/your_application.py onto the badge&lt;br /&gt;
# Restart the badge&lt;br /&gt;
&lt;br /&gt;
== Running example code ==&lt;br /&gt;
There is [https://github.com/geekscape/aiko_engine_mp/tree/master/examples example code] which has a number of examples in it, including a snake game and a demo of how to use various badge functions.&lt;br /&gt;
&lt;br /&gt;
# From your commandline on your computer, use mpfshell to put whatever example code you want onto the badge.&lt;br /&gt;
# To run example code, you can use the &amp;quot;emergency stop&amp;quot; function to halt any other applications and put you in the repl.&lt;br /&gt;
## Touch both of the bottom spots on the sliders&lt;br /&gt;
## Reboot the badge&lt;br /&gt;
# Now at the repl prompt, type (replace the name of the module as appropriate for the code you want to run): &lt;br /&gt;
&lt;br /&gt;
Use examples.game_snake as example:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
from examples.game_snake import run&lt;br /&gt;
run()&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ctrl-c to halt operation and return to the repl prompt.&lt;br /&gt;
&lt;br /&gt;
= Hardware pinout =&lt;br /&gt;
&lt;br /&gt;
You can get the schematic and pin mapping on this page: https://github.com/CCHS-Melbourne/Swag-Badge/blob/master/swag-badge-schematic.pdf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- GPIO0 : left breakout pin4&lt;br /&gt;
- GPIO2 : left breakout pin3&lt;br /&gt;
&lt;br /&gt;
- GPIO4 : SCL (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO5 : SDA (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO12/15: slider #1&lt;br /&gt;
- GPIO13: left breakout pin3&lt;br /&gt;
- GPIO14/27: slider #2 (can be used as VSPI CS/SS#2 and #1 of if one SPI device only, CS is wired to GND)&lt;br /&gt;
- GPIO16: left switch  (under screen #1)&lt;br /&gt;
- GPIO17: right switch (under screen #2)&lt;br /&gt;
&lt;br /&gt;
- GPIO18: SAO3 pin3 + LB pin7  (also VSPI SCL/SCK/CLK/D0)&lt;br /&gt;
- GPIO23: SAO3 pin4            (also VSPI SDA/SDI/MOSI/D1)&lt;br /&gt;
&lt;br /&gt;
- GPIO19: SAO1 pin4&lt;br /&gt;
- GPIO22: SAO1 pin3 (also onboard blue LED in the back)&lt;br /&gt;
&lt;br /&gt;
- GPIO21: unused but not wired on this chip&lt;br /&gt;
&lt;br /&gt;
- GPIO25: SAO4 pin4 + RB pin6  (also VSPI DC/A0/RS)&lt;br /&gt;
- GPIO26: SAO4 pin3 + RB pin7  (also VSPI RES/RST)&lt;br /&gt;
&lt;br /&gt;
- GPIO27: free (pin available on the chip, not routed anywhere)&lt;br /&gt;
&lt;br /&gt;
- GPIO32: SAO2 pin3 + RB pin4 (touch pin, can be used with SAO tux foot or nose touchpad) &lt;br /&gt;
- GPIO33: SAO2 pin4 + RB pin5 (touch pin, can be used with SAO tux foot or nose touchpad)&lt;br /&gt;
&lt;br /&gt;
- GPIO34: right breakout pin2 (input only)&lt;br /&gt;
- GPIO35: right breakout pin3 (input only)&lt;br /&gt;
&lt;br /&gt;
- GPIO36: unused but not wired on this chip (input only)&lt;br /&gt;
- GPIO39: unused but not wired on this chip (input only)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Hardware SPI for a device like SSD1331 ==&lt;br /&gt;
ESP32 has 2 DMA capable hardware SPI busses usable by the user: SPI2/HSPI and SPI3/VSPI (see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/spi_master.html and https://github.com/espressif/arduino-esp32/blob/master/libraries/SPI/examples/SPI_Multiple_Buses/SPI_Multiple_Buses.ino for how to use them at the same time ). The important note in the espressif doc is that if you do not use the dedicated default HWSPI pins, they get routed through a hardware MUX and your maximum SPI speed is lowered from 80Mhz to 40Mhz.&lt;br /&gt;
&lt;br /&gt;
If you would like to connect an SPI device like an SSD1331 96x64 color TFT, here are default hardware pin numbers, and pins you can use for non SPI signals (RES/RST, DC/A0/RS, and CS/SS):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  SD1331 Pin	        ESP32	ESP32&lt;br /&gt;
1 GND                   VSPI    HSPI &lt;br /&gt;
2 VCC&lt;br /&gt;
3 SCL/SCK/CLK/D0	18	14   &lt;br /&gt;
4 SDA/SDI/MOSI/D1	23	13   &lt;br /&gt;
---- 2 pins above and MISO are HWSPI, pins below are anything&lt;br /&gt;
---- RST is not part of SPI, it&#039;s an out of band signal to reset a TFT&lt;br /&gt;
---- This could be wired to the ESP32 EN(reset) pin&lt;br /&gt;
5 RES/RST		26	26   &lt;br /&gt;
---- Data/Command pin is not part of SPI but used to tell the TFT if incoming SPI&lt;br /&gt;
---- data is actually a command, or pixel data.&lt;br /&gt;
6 DC/A0/RS (data)	25	25   &lt;br /&gt;
---- Cable select chooses which SPI device we&#039;re talking to, if there is only&lt;br /&gt;
---- one, it can be tied to ground. Any pin is fine&lt;br /&gt;
7 CS/SS =&amp;gt; GND	        27	15   &lt;br /&gt;
&lt;br /&gt;
---- MISO is not used to talk to TFTs, and is a hardware pin, but unused here&lt;br /&gt;
  MISO		        19	12    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
pins 12/13/14 are already used by the badge, but 18/19/23 are usable (SAO3 and SAO1), and since MISO is unused, you could also assign it to GPIO21 which isn&#039;t wired at all on the lolin lite chip.  &lt;br /&gt;
If you&#039;d also like to keep SAO4 usable (25/26), you can wire CS/SS to ground to free up pin 27, move DC/AO/RS to pin 27, and free up pin 26 (RST) by wiring RST to the ESP32 ENA pin, which should issue a TFT reset every time the ESP32 is reset.&lt;br /&gt;
&lt;br /&gt;
End result: https://youtu.be/TYItVAa4tJY&lt;br /&gt;
&lt;br /&gt;
= Extensions: Adding a SAO =&lt;br /&gt;
* provided by others: look at [https://www.tindie.com/search/?q=SAO Tindie]&lt;br /&gt;
* [[Swagbadge2021_SAO|Build your own]]&lt;br /&gt;
&lt;br /&gt;
= Extensions: Writing your own applications =&lt;br /&gt;
&lt;br /&gt;
Between when we ship the board and when it arrives, there might be some changes to the software framework (Aiko). Here&#039;s how to update it. Or perhaps you&#039;re interested in writing your own applications? &lt;br /&gt;
&lt;br /&gt;
* [[Swagbadge2021_UpdatingSoftware|Updating the Software]]&lt;br /&gt;
* [[Swagbadge2021_SoftwareDev|Writing your own badge programs]]&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1370</id>
		<title>Swagbadge2021 GettingStarted</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1370"/>
		<updated>2021-02-08T05:31:36Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Hardware pinout */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Getting started with the Swagbadge =&lt;br /&gt;
&lt;br /&gt;
== Support ==&lt;br /&gt;
* The [https://spectrum.chat/lca2021-swagbadge Swag Badge Spectrum chat] is a place where the badge team hangs out, ready to answer your questions.&lt;br /&gt;
&lt;br /&gt;
== My package arrived in the mail, first steps. ==&lt;br /&gt;
* Your package should contain your badge, and some other goodies! &lt;br /&gt;
** [[File:swagbadgepackage.jpg|400px|alt=Image showing the contents of the swagbag package]]&lt;br /&gt;
** Badge&lt;br /&gt;
** SAO headers (x 4)&lt;br /&gt;
** SAO proto boards (x 2)&lt;br /&gt;
** SAO tux board&lt;br /&gt;
** Lanyard&lt;br /&gt;
** Stickers&lt;br /&gt;
** Instructions&lt;br /&gt;
* Take off the protective cases to reveal the screens.&lt;br /&gt;
* Powering it up&lt;br /&gt;
** Insert a micro USB cable into the badge and connect the other end to a USB port on your computer or USB power source.&lt;br /&gt;
** A green light should glow on the rear of the board, and a title appear across the two screens.&lt;br /&gt;
* Turning it on and off again&lt;br /&gt;
** Plugging/unplugging it is fine. Usually the badge isn&#039;t running anything intensely enough that just unpowering it would cause a problem.&lt;br /&gt;
* On bootup, you should see:&lt;br /&gt;
** The OLED screens will display &amp;quot;Aiko&amp;quot; and a version number as a title&lt;br /&gt;
** It will also display something else to tell you to set up your wifi.&lt;br /&gt;
&lt;br /&gt;
== Getting it on your network ==&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - wireless ===&lt;br /&gt;
&lt;br /&gt;
The first time you boot your badge, it won&#039;t know how to talk to your wifi network, so it creates its own temporary wifi network for you to connect to, so you can configure it.&lt;br /&gt;
&lt;br /&gt;
* Start your badge by plugging it in.&lt;br /&gt;
* The screens on your badge will say &amp;lt;code&amp;gt;Configure WiFi:&amp;lt;/code&amp;gt; &lt;br /&gt;
   [[File:configurewifi-1.png|300px]]&lt;br /&gt;
* Use your phone (or computer) to change wifi networks to use the badge. The badge wifi name starts with &amp;lt;code&amp;gt;aiko&amp;lt;/code&amp;gt; followed by some numbers/letters. &lt;br /&gt;
   [[File:configurewifi-2.png|200px]] -&amp;gt; [[File:configurewifi-3.png|200px]]&lt;br /&gt;
* Once you&#039;re connected to the badge wifi, open a web browser on that device to the IP address shown on the screens. Something like &amp;lt;code&amp;gt;http://192.168.4.1&amp;lt;/code&amp;gt; &lt;br /&gt;
   [[File:configurewifi-5.png|300px]]&lt;br /&gt;
* You&#039;ll be prompted to enter your wifi SSID and wifi password. &#039;&#039;&#039;Note: Your device can only use a 2.4GHz network&#039;&#039;&#039;: it is not compatible with 5GHz WiFi.&lt;br /&gt;
* The badge will restart using the credentials you&#039;ve provided and it will shut down its wifi access point. &lt;br /&gt;
   [[File:configurewifi-4.png|300px]]&lt;br /&gt;
* Your phone/computer will go back to using its usual wifi network and badge is now online!&lt;br /&gt;
&lt;br /&gt;
Note: If you are using an Android device to link the badge to your WiFi, it will pop up a dialog to say you are switching to a network that doesn&#039;t have Internet access and ask if you want to switch back. Select &amp;quot;Keep&amp;quot; to stay on the badge&#039;s temporary access point.&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - commandline with mpfshell ===&lt;br /&gt;
&lt;br /&gt;
If the above guide to setting up via the wifi AP (access point) doesn&#039;t work, you can put a configuration file onto the badge. You&#039;ll need a Python environment to do so, which you&#039;ll need anyway if you plan on writing your own badge software applications.&lt;br /&gt;
&lt;br /&gt;
* Start by getting [[Swagbadge2021_UpdatingSoftware|a copy of the aiko firmware, and installing mpfshell]]&lt;br /&gt;
* &#039;&#039;Note: Your device can only talk to a 2.4GHz network: it is not compatible with 5GHz.&#039;&#039;&lt;br /&gt;
* Edit aiko_engine_mp/configuration/net.py and insert the details of your SSID and password.&lt;br /&gt;
* use mpfshell: &amp;lt;code&amp;gt;mpfshell -o COM3&amp;lt;/code&amp;gt; (substitute the com port/tty of your badge)&lt;br /&gt;
* &amp;lt;code&amp;gt;put configuration/net.py configuration/net.py&amp;lt;/code&amp;gt;&lt;br /&gt;
* fire up repl to view the console log &lt;br /&gt;
* You can now restart your device&lt;br /&gt;
* On bootup it should now talk to your network and you can see it on the console log.&lt;br /&gt;
&lt;br /&gt;
Your badge will display its connection status on the screens.&lt;br /&gt;
&lt;br /&gt;
= Running pre-installed applications =&lt;br /&gt;
&lt;br /&gt;
== Aiko&#039;s minimal Swagbadge application ==&lt;br /&gt;
At the moment the badge by default a basic &amp;quot;Swagbadge&amp;quot; application within the Aiko framework. This application&lt;br /&gt;
* has a thread to keep wifi running, &lt;br /&gt;
* has a thread to stay connected to (our Australian, private) mqtt server&lt;br /&gt;
* has a thread to display a rotating header across the two oleds.&lt;br /&gt;
&lt;br /&gt;
You can now talk to your badge [[Swagbadge2021_MQTT|using MQTT messages]].&lt;br /&gt;
&lt;br /&gt;
== Running other applications ==&lt;br /&gt;
At the moment, &amp;quot;swagbadge&amp;quot; is the only application that&#039;s for use with the badge. &lt;br /&gt;
&lt;br /&gt;
There are [https://github.com/geekscape/aiko_engine_mp/tree/master/applications other applications] in the repo which are for other places the Aiko framework has been used.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve written an application of your own and want to run that by default on badge startup, &lt;br /&gt;
# edit your local copy of configuration/main.py and change the value of the &amp;quot;application&amp;quot; to point to your new application.&lt;br /&gt;
# using mpfshell, &#039;put&#039; configuration/main.py and applications/your_application.py onto the badge&lt;br /&gt;
# Restart the badge&lt;br /&gt;
&lt;br /&gt;
== Running example code ==&lt;br /&gt;
There is [https://github.com/geekscape/aiko_engine_mp/tree/master/examples example code] which has a number of examples in it, including a snake game and a demo of how to use various badge functions.&lt;br /&gt;
&lt;br /&gt;
# From your commandline on your computer, use mpfshell to put whatever example code you want onto the badge.&lt;br /&gt;
# To run example code, you can use the &amp;quot;emergency stop&amp;quot; function to halt any other applications and put you in the repl.&lt;br /&gt;
## Touch both of the bottom spots on the sliders&lt;br /&gt;
## Reboot the badge&lt;br /&gt;
# Now at the repl prompt, type (replace the name of the module as appropriate for the code you want to run): &lt;br /&gt;
&lt;br /&gt;
Use examples.game_snake as example:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
from examples.game_snake import run&lt;br /&gt;
run()&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ctrl-c to halt operation and return to the repl prompt.&lt;br /&gt;
&lt;br /&gt;
= Hardware pinout =&lt;br /&gt;
&lt;br /&gt;
You can get the schematic and pin mapping on this page: https://github.com/CCHS-Melbourne/Swag-Badge/blob/master/swag-badge-schematic.pdf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- GPIO0 : left breakout pin4&lt;br /&gt;
- GPIO2 : left breakout pin3&lt;br /&gt;
&lt;br /&gt;
- GPIO4 : SCL (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO5 : SDA (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO12/15: slider #1&lt;br /&gt;
- GPIO13: left breakout pin3&lt;br /&gt;
- GPIO14/27: slider #2 (can be used as VSPI CS/SS#2 and #1 of if one SPI device only, CS is wired to GND)&lt;br /&gt;
- GPIO16: left switch  (under screen #1)&lt;br /&gt;
- GPIO17: right switch (under screen #2)&lt;br /&gt;
&lt;br /&gt;
- GPIO18: SAO3 pin3 + LB pin7  (also VSPI SCL/SCK/CLK/D0)&lt;br /&gt;
- GPIO23: SAO3 pin4            (also VSPI SDA/SDI/MOSI/D1)&lt;br /&gt;
&lt;br /&gt;
- GPIO19: SAO1 pin4&lt;br /&gt;
- GPIO22: SAO1 pin3 (also onboard blue LED in the back)&lt;br /&gt;
&lt;br /&gt;
- GPIO21: unused but not wired on this chip&lt;br /&gt;
&lt;br /&gt;
- GPIO25: SAO4 pin4 + RB pin6  (also VSPI DC/A0/RS)&lt;br /&gt;
- GPIO26: SAO4 pin3 + RB pin7  (also VSPI RES/RST)&lt;br /&gt;
&lt;br /&gt;
- GPIO27: free (pin available on the chip, not routed anywhere)&lt;br /&gt;
&lt;br /&gt;
- GPIO32: SAO2 pin3 + RB pin4 (touch pin, can be used with SAO tux foot or nose touchpad) &lt;br /&gt;
- GPIO33: SAO2 pin4 + RB pin5 (touch pin, can be used with SAO tux foot or nose touchpad)&lt;br /&gt;
&lt;br /&gt;
- GPIO34: right breakout pin2 (input only)&lt;br /&gt;
- GPIO35: right breakout pin3 (input only)&lt;br /&gt;
&lt;br /&gt;
- GPIO36: unused but not wired on this chip (input only)&lt;br /&gt;
- GPIO39: unused but not wired on this chip (input only)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Hardware SPI for a device like SSD1331 ==&lt;br /&gt;
ESP32 has 2 DMA capable hardware SPI busses usable by the user: SPI2/HSPI and SPI3/VSPI (see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/spi_master.html and https://github.com/espressif/arduino-esp32/blob/master/libraries/SPI/examples/SPI_Multiple_Buses/SPI_Multiple_Buses.ino for how to use them at the same time ). The important note in the espressif doc is that if you do not use the dedicated default HWSPI pins, they get routed through a hardware MUX and your maximum SPI speed is lowered from 80Mhz to 40Mhz.&lt;br /&gt;
&lt;br /&gt;
If you would like to connect an SPI device like an SSD1331 96x64 color TFT, here are default hardware pin numbers, and pins you can use for non SPI signals (RES/RST, DC/A0/RS, and CS/SS):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  SD1331 Pin	        ESP32	ESP32&lt;br /&gt;
1 GND                   VSPI    HSPI &lt;br /&gt;
2 VCC&lt;br /&gt;
3 SCL/SCK/CLK/D0	18	14   &lt;br /&gt;
4 SDA/SDI/MOSI/D1	23	13   &lt;br /&gt;
---- 2 pins above and MISO are HWSPI, pins below are anything&lt;br /&gt;
---- RST is not part of SPI, it&#039;s an out of band signal to reset a TFT&lt;br /&gt;
---- This could be wired to the ESP32 EN(reset) pin&lt;br /&gt;
5 RES/RST		26	26   &lt;br /&gt;
---- Data/Command pin is not part of SPI but used to tell the TFT if incoming SPI&lt;br /&gt;
---- data is actually a command, or pixel data.&lt;br /&gt;
6 DC/A0/RS (data)	25	25   &lt;br /&gt;
---- Cable select chooses which SPI device we&#039;re talking to, if there is only&lt;br /&gt;
---- one, it can be tied to ground. Any pin is fine&lt;br /&gt;
7 CS/SS =&amp;gt; GND	        27	15   &lt;br /&gt;
&lt;br /&gt;
---- MISO is not used to talk to TFTs, and is a hardware pin, but unused here&lt;br /&gt;
  MISO		        19	12    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
pins 12/13/14 are already used by the badge, but 18/19/23 are usable (SAO3 and SAO1), and since MISO is unused, you could also assign it to GPIO21 which isn&#039;t wired at all on the lolin lite chip.  &lt;br /&gt;
If you&#039;d also like to keep SAO4 usable (25/26), you can wire CS/SS to ground, move DC/AO/RS to pin 27, and free up pin 26 (RST) by wiring RST to the ESP32 ENA pin, which should issue a TFT reset every time the ESP32 is reset.&lt;br /&gt;
&lt;br /&gt;
End result: https://youtu.be/TYItVAa4tJY&lt;br /&gt;
&lt;br /&gt;
= Extensions: Adding a SAO =&lt;br /&gt;
* provided by others: look at [https://www.tindie.com/search/?q=SAO Tindie]&lt;br /&gt;
* [[Swagbadge2021_SAO|Build your own]]&lt;br /&gt;
&lt;br /&gt;
= Extensions: Writing your own applications =&lt;br /&gt;
&lt;br /&gt;
Between when we ship the board and when it arrives, there might be some changes to the software framework (Aiko). Here&#039;s how to update it. Or perhaps you&#039;re interested in writing your own applications? &lt;br /&gt;
&lt;br /&gt;
* [[Swagbadge2021_UpdatingSoftware|Updating the Software]]&lt;br /&gt;
* [[Swagbadge2021_SoftwareDev|Writing your own badge programs]]&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_MQTT&amp;diff=1332</id>
		<title>Swagbadge2021 MQTT</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_MQTT&amp;diff=1332"/>
		<updated>2021-01-23T22:08:14Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Making your badge perform */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= About MQTT = &lt;br /&gt;
&lt;br /&gt;
MQTT is a lightweight message platform that uses individual topics (like a slack channel) that people can send messages to (called publishing) or listen for messages on (called subscribing).&lt;br /&gt;
&lt;br /&gt;
MQTT is designed for use on IoT devices. Check out [https://en.wikipedia.org/wiki/MQTT Wikipedia] for some background or [https://mqtt.org/ mqtt.org] for more information on it generally.&lt;br /&gt;
&lt;br /&gt;
== About the LCA Swagbadge MQTT server ==&lt;br /&gt;
&lt;br /&gt;
The badges have MQTT configured to talk to a dedicated server hosted by Andy Gelme, one of the OHMC organisers. We have done this for security and privacy reasons, and because it gives us an Australian server so it&#039;s faster.&lt;br /&gt;
&lt;br /&gt;
This server is at &amp;lt;code&amp;gt;101.181.46.180&amp;lt;/code&amp;gt;, the configuration for which is held on the badge at [https://github.com/geekscape/aiko_engine_mp/blob/master/configuration/mqtt.py configuration/mqtt.py]. The server has some special features:&lt;br /&gt;
* The &#039;&#039;upgrade/&#039;&#039; topic path prefix is public read: only Jon and Andy can update it.&lt;br /&gt;
* The &#039;&#039;aiko/&#039;&#039; topic path prefix is public read/write&lt;br /&gt;
* The &#039;&#039;public/&#039;&#039; topic path prefix is available for everyone to read/write&lt;br /&gt;
* The &#039;&#039;secret/&#039;&#039; topic path prefix is write-only&lt;br /&gt;
* We have some server monitoring to look for things snooping for all the channels, or who aren&#039;t using aiko/on a badge, and mitigations in the event a badge goes beserk and starts a spamming DOS attack.&lt;br /&gt;
&lt;br /&gt;
You are welcome to change which MQTT server your badge uses, by updating the mqtt.py configuration file. Some publicly hosted alternatives are provided (commented out) in the config.&lt;br /&gt;
&lt;br /&gt;
= Controlling your badge over MQTT =&lt;br /&gt;
&lt;br /&gt;
== Making your badge perform ==&lt;br /&gt;
&lt;br /&gt;
The easiest thing to do is send messages to show up on your screens.&lt;br /&gt;
&lt;br /&gt;
# Install an mqtt client on your machine&lt;br /&gt;
# Connect to the mqtt server (if you forget what it is, the IP address is shown on bootup)&lt;br /&gt;
# Using your badge&#039;s topic (public/esp32_your_badge_id/0/in) send it a message&lt;br /&gt;
&lt;br /&gt;
Messages are usually in the form of &amp;lt;code&amp;gt;(component:command arguments)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
mosquitto_sub -h 101.181.46.180 -t public/esp32_id/0/# (will receive messages output by the badge like &amp;quot;(boot v04 swagbadge)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
mosquitto_sub -h 101.181.46.180 -t public/esp32_id/#  (shows message sent to the badge)&lt;br /&gt;
&lt;br /&gt;
mosquitto_sub -h 101.181.46.180 -t public/# (show all messages for all badges)&lt;br /&gt;
&lt;br /&gt;
mosquitto_pub -h 101.181.46.180 -t public/esp32_id/0/in -m &amp;quot;(oled:clear)&amp;quot;  &lt;br /&gt;
&lt;br /&gt;
mosquitto_pub -h 101.181.46.180 -t public/esp32_id/0/in -m &amp;quot;(oled:pixel 64 32)&amp;quot;  &lt;br /&gt;
&lt;br /&gt;
mosquitto_pub -h 101.181.46.180 -t public/esp32_id/0/in -m &amp;quot;(oled:text 0 50 Hello World)&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== OLED messages ===&lt;br /&gt;
;(oled&amp;amp;#58;clear)&lt;br /&gt;
: clears both screens&lt;br /&gt;
;(oled&amp;amp;#58;log Hello World!)&lt;br /&gt;
: writes a message along the bottom of the screens, scrolling up whatever is there out of the way&lt;br /&gt;
; (oled&amp;amp;#58;pixel x y)&lt;br /&gt;
: lights a pixel at that spot&lt;br /&gt;
; (oled&amp;amp;#58;text x y This is a test !)&lt;br /&gt;
: Puts some text at the position x,y. It will be displayed over the top of whatever&#039;s there.&lt;br /&gt;
&lt;br /&gt;
If you&#039;d like to make your application MQTT aware, take a look at the [https://github.com/geekscape/aiko_engine_mp/blob/master/lib/aiko/oled.py oled code].&lt;br /&gt;
&lt;br /&gt;
= Using MQTT on your badge =&lt;br /&gt;
&lt;br /&gt;
== Over Aiko ==&lt;br /&gt;
&lt;br /&gt;
Aiko has some convenience handlers to make using MQTT easier.&lt;br /&gt;
&lt;br /&gt;
Behind the scenes, Aiko routes messages to the specific handlers matching a given topic and supports multiple handlers “listening” to various specific topics.  There is an exception handler wrapped around every message handler, so that the overall MQTT thread doesn’t fail. &lt;br /&gt;
&lt;br /&gt;
=== Receiving a message and taking action ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Subscribe to a topic&#039;&#039;&#039;&lt;br /&gt;
Update &#039;&#039;configuration/mqtt.py&#039;&#039; and add in the topic to the &amp;lt;code&amp;gt;topic_subscribe&amp;lt;/code&amp;gt; list&lt;br /&gt;
    &amp;quot;topic_subscribe&amp;quot;: [ &amp;quot;$me/in&amp;quot;, &amp;quot;$me/exec&amp;quot;, upgrade_topic, &amp;quot;YOUR_TOPIC&amp;quot; ],&lt;br /&gt;
&lt;br /&gt;
If you want to listen/subscribe to all sub-topics, use a &amp;lt;code&amp;gt;#&amp;lt;/code&amp;gt; at the end. For example &amp;lt;code&amp;gt;public/chocolate/#&amp;lt;/code&amp;gt; will listen to public/chocolate and public/chocolate/lindt and public/chocolate/kokoblack and public/chocolate/ganache&lt;br /&gt;
&lt;br /&gt;
See https://github.com/geekscape/aiko_engine_mp/blob/master/configuration/mqtt.py#L13 as well as line 132 and 63&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Handle messages on that topic&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define a message handler function, which takes a topic argument (in case you use the same message handler for multiple topics), and the payload (the message that was seen)&lt;br /&gt;
     def on_message(topic, payload_in):&lt;br /&gt;
        print(topic + &amp;quot;: &amp;quot; + payload_in)&lt;br /&gt;
&lt;br /&gt;
Add this handler function to the MQTT client: this is typically done in your application&#039;s initialise() method.&lt;br /&gt;
    mqtt.add_message_handler(on_message, &amp;quot;YOUR_TOPIC&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example code&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Here is a complete application example … https://github.com/geekscape/aiko_engine_mp/blob/master/applications/step_controller.py&lt;br /&gt;
&lt;br /&gt;
In this case, Aiko’s general MQTT on_message() handler will route all incoming messages to the specific handlers matching a given topic and supports multiple handlers “listening” to various specific topics.  There is an exception handler wrapped around every message handler … so that the MQTT thread doesn’t fail.  And over time Aiko’s error handling will improve, e.g re-subscribe to all MQTT topics on reconnection, etc.  At some point, Aiko will provide the heavy lifting for encrypted message publish / subscribe.  Finally, once Aiko Services (a general purpose distributed / embedded system) is released, then our ESP32 devices can become first-class citizens of a broader distributed service-based network (perhaps a month or so away).  Aiko also supports some “dangerous” fun, like opt-in enabling receiving microPython code as an MQTT message and executing it (obviously this is dangerous)&lt;br /&gt;
&lt;br /&gt;
=== Publishing a message ===&lt;br /&gt;
&lt;br /&gt;
Use the aiko mqtt client object to send a message.&lt;br /&gt;
&lt;br /&gt;
   from aiko.mqtt import client&lt;br /&gt;
   client.publish(topic, message)&lt;br /&gt;
&lt;br /&gt;
Which topic to use? On our LCA server, we are constrained to only use the &#039;public&#039; and &#039;aiko&#039; prefixed topics.&lt;br /&gt;
&lt;br /&gt;
To keep things neat and orderly, we recommend using&lt;br /&gt;
;public/esp32_SERIAL_ID/YOUR_TOPIC_HERE: for topics specific to your personal swagbadge&lt;br /&gt;
;public/SUBJECT/YOUR_TOPIC_HERE: for topics intended to share information with multiple swagbadges&lt;br /&gt;
&lt;br /&gt;
== Going direct to MQTT ==&lt;br /&gt;
&lt;br /&gt;
Since Aiko already makes an MQTT connection (to our server), you don’t need to make another MQTT connect, unless you want to interact with multiple MQTT servers (beyond the MQTT server already configured in &#039;&#039;configuration/mqtt.py&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
You can use the Aiko MQTT client object reference to access any of the MQTT library functions …&lt;br /&gt;
   &amp;gt;&amp;gt;&amp;gt; import aiko.mqtt.client as mqttclient&lt;br /&gt;
   &amp;gt;&amp;gt;&amp;gt; help(aiko.mqtt.client)&lt;br /&gt;
&lt;br /&gt;
[https://github.com/geekscape/aiko_engine_mp/blob/master/lib/umqtt/simple.py All of the available MQTT Client functions]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== MQTT message publishing ===&lt;br /&gt;
&lt;br /&gt;
you can always use the Aiko MQTT client object to publish messages to any topic … to which you have access permission.&lt;br /&gt;
On our MQTT server, that is read / write access to aiko/# and public/#.  By default, each #swagbadge will be using public/esp32_SERIAL_ID/0/# as their own topic path prefix and using specific topic paths under that, e.g public/esp32_SERIAL_ID/0/in (all #swagbadges subscribe to that topic path aka $me/in … where Aiko substitutes the topic path prefix for $me) and publish on public/esp32_SERIAL_ID/0/out:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    aiko.mqtt.client.publish(topic, payload)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So for example, you could use:&lt;br /&gt;
* public/esp32_SERIAL_ID/WHATEVER_YOU_LIKE … recommended for topics specific to interacting with your #swagbadge&lt;br /&gt;
* public/nicola/WHATEVER_YOU_LIKE … recommended for topics where you’d like to share information with a bunch of #swagbadges, i.e not specific to your #swagbadge&lt;br /&gt;
&lt;br /&gt;
It doesn’t matter too much apart from being tidy and organised.  If everyone follows reasonable conventions, then it is more orderly, e.g like taking care of a filesystem layout.&lt;br /&gt;
&lt;br /&gt;
= Encrypting messages with your badge =&lt;br /&gt;
&lt;br /&gt;
Placeholder text.&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_MQTT&amp;diff=1331</id>
		<title>Swagbadge2021 MQTT</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_MQTT&amp;diff=1331"/>
		<updated>2021-01-23T21:46:23Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Controlling your badge over MQTT */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= About MQTT = &lt;br /&gt;
&lt;br /&gt;
MQTT is a lightweight message platform that uses individual topics (like a slack channel) that people can send messages to (called publishing) or listen for messages on (called subscribing).&lt;br /&gt;
&lt;br /&gt;
MQTT is designed for use on IoT devices. Check out [https://en.wikipedia.org/wiki/MQTT Wikipedia] for some background or [https://mqtt.org/ mqtt.org] for more information on it generally.&lt;br /&gt;
&lt;br /&gt;
== About the LCA Swagbadge MQTT server ==&lt;br /&gt;
&lt;br /&gt;
The badges have MQTT configured to talk to a dedicated server hosted by Andy Gelme, one of the OHMC organisers. We have done this for security and privacy reasons, and because it gives us an Australian server so it&#039;s faster.&lt;br /&gt;
&lt;br /&gt;
This server is at &amp;lt;code&amp;gt;101.181.46.180&amp;lt;/code&amp;gt;, the configuration for which is held on the badge at [https://github.com/geekscape/aiko_engine_mp/blob/master/configuration/mqtt.py configuration/mqtt.py]. The server has some special features:&lt;br /&gt;
* The &#039;&#039;upgrade/&#039;&#039; topic path prefix is public read: only Jon and Andy can update it.&lt;br /&gt;
* The &#039;&#039;aiko/&#039;&#039; topic path prefix is public read/write&lt;br /&gt;
* The &#039;&#039;public/&#039;&#039; topic path prefix is available for everyone to read/write&lt;br /&gt;
* The &#039;&#039;secret/&#039;&#039; topic path prefix is write-only&lt;br /&gt;
* We have some server monitoring to look for things snooping for all the channels, or who aren&#039;t using aiko/on a badge, and mitigations in the event a badge goes beserk and starts a spamming DOS attack.&lt;br /&gt;
&lt;br /&gt;
You are welcome to change which MQTT server your badge uses, by updating the mqtt.py configuration file. Some publicly hosted alternatives are provided (commented out) in the config.&lt;br /&gt;
&lt;br /&gt;
= Controlling your badge over MQTT =&lt;br /&gt;
&lt;br /&gt;
== Making your badge perform ==&lt;br /&gt;
&lt;br /&gt;
The easiest thing to do is send messages to show up on your screens.&lt;br /&gt;
&lt;br /&gt;
# Install an mqtt client on your machine&lt;br /&gt;
# Connect to the mqtt server (if you forget what it is, the IP address is shown on bootup)&lt;br /&gt;
# Using your badge&#039;s topic (public/esp32_your_badge_id/0/in) send it a message&lt;br /&gt;
&lt;br /&gt;
Messages are usually in the form of &amp;lt;code&amp;gt;(component:command arguments)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
mosquitto_sub -h 101.181.46.180 -t public/esp32_id/0/out (may receive messages output by the badge)&lt;br /&gt;
&lt;br /&gt;
mosquitto_sub -h 101.181.46.180 -t public/esp32_id/#  (shows message sent to the badge)&lt;br /&gt;
&lt;br /&gt;
mosquitto_sub -h 101.181.46.180 -t public/# (show all messages for all badges)&lt;br /&gt;
&lt;br /&gt;
mosquitto_pub -h 101.181.46.180 -t public/esp32_id/0/in -m &amp;quot;(oled:clear)&amp;quot;  &lt;br /&gt;
&lt;br /&gt;
mosquitto_pub -h 101.181.46.180 -t public/esp32_id/0/in -m &amp;quot;(oled:pixel 64 32)&amp;quot;  &lt;br /&gt;
&lt;br /&gt;
mosquitto_pub -h 101.181.46.180 -t public/esp32_id/0/in -m &amp;quot;(oled:text 0 50 Hello World)&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== OLED messages ===&lt;br /&gt;
;(oled&amp;amp;#58;clear)&lt;br /&gt;
: clears both screens&lt;br /&gt;
;(oled&amp;amp;#58;log Hello World!)&lt;br /&gt;
: writes a message along the bottom of the screens, scrolling up whatever is there out of the way&lt;br /&gt;
; (oled&amp;amp;#58;pixel x y)&lt;br /&gt;
: lights a pixel at that spot&lt;br /&gt;
; (oled&amp;amp;#58;text x y This is a test !)&lt;br /&gt;
: Puts some text at the position x,y. It will be displayed over the top of whatever&#039;s there.&lt;br /&gt;
&lt;br /&gt;
If you&#039;d like to make your application MQTT aware, take a look at the [https://github.com/geekscape/aiko_engine_mp/blob/master/lib/aiko/oled.py oled code].&lt;br /&gt;
&lt;br /&gt;
= Using MQTT on your badge =&lt;br /&gt;
&lt;br /&gt;
== Over Aiko ==&lt;br /&gt;
&lt;br /&gt;
Aiko has some convenience handlers to make using MQTT easier.&lt;br /&gt;
&lt;br /&gt;
Behind the scenes, Aiko routes messages to the specific handlers matching a given topic and supports multiple handlers “listening” to various specific topics.  There is an exception handler wrapped around every message handler, so that the overall MQTT thread doesn’t fail. &lt;br /&gt;
&lt;br /&gt;
=== Receiving a message and taking action ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Subscribe to a topic&#039;&#039;&#039;&lt;br /&gt;
Update &#039;&#039;configuration/mqtt.py&#039;&#039; and add in the topic to the &amp;lt;code&amp;gt;topic_subscribe&amp;lt;/code&amp;gt; list&lt;br /&gt;
    &amp;quot;topic_subscribe&amp;quot;: [ &amp;quot;$me/in&amp;quot;, &amp;quot;$me/exec&amp;quot;, upgrade_topic, &amp;quot;YOUR_TOPIC&amp;quot; ],&lt;br /&gt;
&lt;br /&gt;
If you want to listen/subscribe to all sub-topics, use a &amp;lt;code&amp;gt;#&amp;lt;/code&amp;gt; at the end. For example &amp;lt;code&amp;gt;public/chocolate/#&amp;lt;/code&amp;gt; will listen to public/chocolate and public/chocolate/lindt and public/chocolate/kokoblack and public/chocolate/ganache&lt;br /&gt;
&lt;br /&gt;
See https://github.com/geekscape/aiko_engine_mp/blob/master/configuration/mqtt.py#L13 as well as line 132 and 63&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Handle messages on that topic&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define a message handler function, which takes a topic argument (in case you use the same message handler for multiple topics), and the payload (the message that was seen)&lt;br /&gt;
     def on_message(topic, payload_in):&lt;br /&gt;
        print(topic + &amp;quot;: &amp;quot; + payload_in)&lt;br /&gt;
&lt;br /&gt;
Add this handler function to the MQTT client: this is typically done in your application&#039;s initialise() method.&lt;br /&gt;
    mqtt.add_message_handler(on_message, &amp;quot;YOUR_TOPIC&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example code&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Here is a complete application example … https://github.com/geekscape/aiko_engine_mp/blob/master/applications/step_controller.py&lt;br /&gt;
&lt;br /&gt;
In this case, Aiko’s general MQTT on_message() handler will route all incoming messages to the specific handlers matching a given topic and supports multiple handlers “listening” to various specific topics.  There is an exception handler wrapped around every message handler … so that the MQTT thread doesn’t fail.  And over time Aiko’s error handling will improve, e.g re-subscribe to all MQTT topics on reconnection, etc.  At some point, Aiko will provide the heavy lifting for encrypted message publish / subscribe.  Finally, once Aiko Services (a general purpose distributed / embedded system) is released, then our ESP32 devices can become first-class citizens of a broader distributed service-based network (perhaps a month or so away).  Aiko also supports some “dangerous” fun, like opt-in enabling receiving microPython code as an MQTT message and executing it (obviously this is dangerous)&lt;br /&gt;
&lt;br /&gt;
=== Publishing a message ===&lt;br /&gt;
&lt;br /&gt;
Use the aiko mqtt client object to send a message.&lt;br /&gt;
&lt;br /&gt;
   from aiko.mqtt import client&lt;br /&gt;
   client.publish(topic, message)&lt;br /&gt;
&lt;br /&gt;
Which topic to use? On our LCA server, we are constrained to only use the &#039;public&#039; and &#039;aiko&#039; prefixed topics.&lt;br /&gt;
&lt;br /&gt;
To keep things neat and orderly, we recommend using&lt;br /&gt;
;public/esp32_SERIAL_ID/YOUR_TOPIC_HERE: for topics specific to your personal swagbadge&lt;br /&gt;
;public/SUBJECT/YOUR_TOPIC_HERE: for topics intended to share information with multiple swagbadges&lt;br /&gt;
&lt;br /&gt;
== Going direct to MQTT ==&lt;br /&gt;
&lt;br /&gt;
Since Aiko already makes an MQTT connection (to our server), you don’t need to make another MQTT connect, unless you want to interact with multiple MQTT servers (beyond the MQTT server already configured in &#039;&#039;configuration/mqtt.py&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
You can use the Aiko MQTT client object reference to access any of the MQTT library functions …&lt;br /&gt;
   &amp;gt;&amp;gt;&amp;gt; import aiko.mqtt.client as mqttclient&lt;br /&gt;
   &amp;gt;&amp;gt;&amp;gt; help(aiko.mqtt.client)&lt;br /&gt;
&lt;br /&gt;
[https://github.com/geekscape/aiko_engine_mp/blob/master/lib/umqtt/simple.py All of the available MQTT Client functions]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== MQTT message publishing ===&lt;br /&gt;
&lt;br /&gt;
you can always use the Aiko MQTT client object to publish messages to any topic … to which you have access permission.&lt;br /&gt;
On our MQTT server, that is read / write access to aiko/# and public/#.  By default, each #swagbadge will be using public/esp32_SERIAL_ID/0/# as their own topic path prefix and using specific topic paths under that, e.g public/esp32_SERIAL_ID/0/in (all #swagbadges subscribe to that topic path aka $me/in … where Aiko substitutes the topic path prefix for $me) and publish on public/esp32_SERIAL_ID/0/out:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    aiko.mqtt.client.publish(topic, payload)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So for example, you could use:&lt;br /&gt;
* public/esp32_SERIAL_ID/WHATEVER_YOU_LIKE … recommended for topics specific to interacting with your #swagbadge&lt;br /&gt;
* public/nicola/WHATEVER_YOU_LIKE … recommended for topics where you’d like to share information with a bunch of #swagbadges, i.e not specific to your #swagbadge&lt;br /&gt;
&lt;br /&gt;
It doesn’t matter too much apart from being tidy and organised.  If everyone follows reasonable conventions, then it is more orderly, e.g like taking care of a filesystem layout.&lt;br /&gt;
&lt;br /&gt;
= Encrypting messages with your badge =&lt;br /&gt;
&lt;br /&gt;
Placeholder text.&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_MQTT&amp;diff=1330</id>
		<title>Swagbadge2021 MQTT</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_MQTT&amp;diff=1330"/>
		<updated>2021-01-23T21:31:50Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Going direct to MQTT */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= About MQTT = &lt;br /&gt;
&lt;br /&gt;
MQTT is a lightweight message platform that uses individual topics (like a slack channel) that people can send messages to (called publishing) or listen for messages on (called subscribing).&lt;br /&gt;
&lt;br /&gt;
MQTT is designed for use on IoT devices. Check out [https://en.wikipedia.org/wiki/MQTT Wikipedia] for some background or [https://mqtt.org/ mqtt.org] for more information on it generally.&lt;br /&gt;
&lt;br /&gt;
== About the LCA Swagbadge MQTT server ==&lt;br /&gt;
&lt;br /&gt;
The badges have MQTT configured to talk to a dedicated server hosted by Andy Gelme, one of the OHMC organisers. We have done this for security and privacy reasons, and because it gives us an Australian server so it&#039;s faster.&lt;br /&gt;
&lt;br /&gt;
This server is at &amp;lt;code&amp;gt;101.181.46.180&amp;lt;/code&amp;gt;, the configuration for which is held on the badge at [https://github.com/geekscape/aiko_engine_mp/blob/master/configuration/mqtt.py configuration/mqtt.py]. The server has some special features:&lt;br /&gt;
* The &#039;&#039;upgrade/&#039;&#039; topic path prefix is public read: only Jon and Andy can update it.&lt;br /&gt;
* The &#039;&#039;aiko/&#039;&#039; topic path prefix is public read/write&lt;br /&gt;
* The &#039;&#039;public/&#039;&#039; topic path prefix is available for everyone to read/write&lt;br /&gt;
* The &#039;&#039;secret/&#039;&#039; topic path prefix is write-only&lt;br /&gt;
* We have some server monitoring to look for things snooping for all the channels, or who aren&#039;t using aiko/on a badge, and mitigations in the event a badge goes beserk and starts a spamming DOS attack.&lt;br /&gt;
&lt;br /&gt;
You are welcome to change which MQTT server your badge uses, by updating the mqtt.py configuration file. Some publicly hosted alternatives are provided (commented out) in the config.&lt;br /&gt;
&lt;br /&gt;
= Controlling your badge over MQTT =&lt;br /&gt;
&lt;br /&gt;
== Making your badge perform ==&lt;br /&gt;
&lt;br /&gt;
The easiest thing to do is send messages to show up on your screens.&lt;br /&gt;
&lt;br /&gt;
# Install an mqtt client on your machine&lt;br /&gt;
# Connect to the mqtt server (if you forget what it is, the IP address is shown on bootup)&lt;br /&gt;
# Using your badge&#039;s topic (public/esp32_your_badge_id/0/in) send it a message&lt;br /&gt;
&lt;br /&gt;
Messages are usually in the form of &amp;lt;code&amp;gt;(component:command arguments)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
mosquitto_sub -h 101.181.46.180 -t public/esp32_id/0 &amp;amp;   &amp;lt;&amp;lt; does this receive anything?&lt;br /&gt;
&lt;br /&gt;
mosquitto_pub -h 101.181.46.180 -t public/esp32_id/0/in -m &amp;quot;(oled:clear)&amp;quot;  &lt;br /&gt;
&lt;br /&gt;
mosquitto_pub -h 101.181.46.180 -t public/esp32_id/0/in -m &amp;quot;(oled:pixel 64 32)&amp;quot;  &lt;br /&gt;
&lt;br /&gt;
mosquitto_pub -h 101.181.46.180 -t public/esp32_id/0/in -m &amp;quot;(oled:text 0 50 Hello World)&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== OLED messages ===&lt;br /&gt;
;(oled&amp;amp;#58;clear)&lt;br /&gt;
: clears both screens&lt;br /&gt;
;(oled&amp;amp;#58;log Hello World!)&lt;br /&gt;
: writes a message along the bottom of the screens, scrolling up whatever is there out of the way&lt;br /&gt;
; (oled&amp;amp;#58;pixel x y)&lt;br /&gt;
: lights a pixel at that spot&lt;br /&gt;
; (oled&amp;amp;#58;text x y This is a test !)&lt;br /&gt;
: Puts some text at the position x,y. It will be displayed over the top of whatever&#039;s there.&lt;br /&gt;
&lt;br /&gt;
If you&#039;d like to make your application MQTT aware, take a look at the [https://github.com/geekscape/aiko_engine_mp/blob/master/lib/aiko/oled.py oled code].&lt;br /&gt;
&lt;br /&gt;
= Using MQTT on your badge =&lt;br /&gt;
&lt;br /&gt;
== Over Aiko ==&lt;br /&gt;
&lt;br /&gt;
Aiko has some convenience handlers to make using MQTT easier.&lt;br /&gt;
&lt;br /&gt;
Behind the scenes, Aiko routes messages to the specific handlers matching a given topic and supports multiple handlers “listening” to various specific topics.  There is an exception handler wrapped around every message handler, so that the overall MQTT thread doesn’t fail. &lt;br /&gt;
&lt;br /&gt;
=== Receiving a message and taking action ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Subscribe to a topic&#039;&#039;&#039;&lt;br /&gt;
Update &#039;&#039;configuration/mqtt.py&#039;&#039; and add in the topic to the &amp;lt;code&amp;gt;topic_subscribe&amp;lt;/code&amp;gt; list&lt;br /&gt;
    &amp;quot;topic_subscribe&amp;quot;: [ &amp;quot;$me/in&amp;quot;, &amp;quot;$me/exec&amp;quot;, upgrade_topic, &amp;quot;YOUR_TOPIC&amp;quot; ],&lt;br /&gt;
&lt;br /&gt;
If you want to listen/subscribe to all sub-topics, use a &amp;lt;code&amp;gt;#&amp;lt;/code&amp;gt; at the end. For example &amp;lt;code&amp;gt;public/chocolate/#&amp;lt;/code&amp;gt; will listen to public/chocolate and public/chocolate/lindt and public/chocolate/kokoblack and public/chocolate/ganache&lt;br /&gt;
&lt;br /&gt;
See https://github.com/geekscape/aiko_engine_mp/blob/master/configuration/mqtt.py#L13 as well as line 132 and 63&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Handle messages on that topic&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define a message handler function, which takes a topic argument (in case you use the same message handler for multiple topics), and the payload (the message that was seen)&lt;br /&gt;
     def on_message(topic, payload_in):&lt;br /&gt;
        print(topic + &amp;quot;: &amp;quot; + payload_in)&lt;br /&gt;
&lt;br /&gt;
Add this handler function to the MQTT client: this is typically done in your application&#039;s initialise() method.&lt;br /&gt;
    mqtt.add_message_handler(on_message, &amp;quot;YOUR_TOPIC&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example code&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Here is a complete application example … https://github.com/geekscape/aiko_engine_mp/blob/master/applications/step_controller.py&lt;br /&gt;
&lt;br /&gt;
In this case, Aiko’s general MQTT on_message() handler will route all incoming messages to the specific handlers matching a given topic and supports multiple handlers “listening” to various specific topics.  There is an exception handler wrapped around every message handler … so that the MQTT thread doesn’t fail.  And over time Aiko’s error handling will improve, e.g re-subscribe to all MQTT topics on reconnection, etc.  At some point, Aiko will provide the heavy lifting for encrypted message publish / subscribe.  Finally, once Aiko Services (a general purpose distributed / embedded system) is released, then our ESP32 devices can become first-class citizens of a broader distributed service-based network (perhaps a month or so away).  Aiko also supports some “dangerous” fun, like opt-in enabling receiving microPython code as an MQTT message and executing it (obviously this is dangerous)&lt;br /&gt;
&lt;br /&gt;
=== Publishing a message ===&lt;br /&gt;
&lt;br /&gt;
Use the aiko mqtt client object to send a message.&lt;br /&gt;
&lt;br /&gt;
   from aiko.mqtt import client&lt;br /&gt;
   client.publish(topic, message)&lt;br /&gt;
&lt;br /&gt;
Which topic to use? On our LCA server, we are constrained to only use the &#039;public&#039; and &#039;aiko&#039; prefixed topics.&lt;br /&gt;
&lt;br /&gt;
To keep things neat and orderly, we recommend using&lt;br /&gt;
;public/esp32_SERIAL_ID/YOUR_TOPIC_HERE: for topics specific to your personal swagbadge&lt;br /&gt;
;public/SUBJECT/YOUR_TOPIC_HERE: for topics intended to share information with multiple swagbadges&lt;br /&gt;
&lt;br /&gt;
== Going direct to MQTT ==&lt;br /&gt;
&lt;br /&gt;
Since Aiko already makes an MQTT connection (to our server), you don’t need to make another MQTT connect, unless you want to interact with multiple MQTT servers (beyond the MQTT server already configured in &#039;&#039;configuration/mqtt.py&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
You can use the Aiko MQTT client object reference to access any of the MQTT library functions …&lt;br /&gt;
   &amp;gt;&amp;gt;&amp;gt; import aiko.mqtt.client as mqttclient&lt;br /&gt;
   &amp;gt;&amp;gt;&amp;gt; help(aiko.mqtt.client)&lt;br /&gt;
&lt;br /&gt;
[https://github.com/geekscape/aiko_engine_mp/blob/master/lib/umqtt/simple.py All of the available MQTT Client functions]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== MQTT message publishing ===&lt;br /&gt;
&lt;br /&gt;
you can always use the Aiko MQTT client object to publish messages to any topic … to which you have access permission.&lt;br /&gt;
On our MQTT server, that is read / write access to aiko/# and public/#.  By default, each #swagbadge will be using public/esp32_SERIAL_ID/0/# as their own topic path prefix and using specific topic paths under that, e.g public/esp32_SERIAL_ID/0/in (all #swagbadges subscribe to that topic path aka $me/in … where Aiko substitutes the topic path prefix for $me) and publish on public/esp32_SERIAL_ID/0/out:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    aiko.mqtt.client.publish(topic, payload)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So for example, you could use:&lt;br /&gt;
* public/esp32_SERIAL_ID/WHATEVER_YOU_LIKE … recommended for topics specific to interacting with your #swagbadge&lt;br /&gt;
* public/nicola/WHATEVER_YOU_LIKE … recommended for topics where you’d like to share information with a bunch of #swagbadges, i.e not specific to your #swagbadge&lt;br /&gt;
&lt;br /&gt;
It doesn’t matter too much apart from being tidy and organised.  If everyone follows reasonable conventions, then it is more orderly, e.g like taking care of a filesystem layout.&lt;br /&gt;
&lt;br /&gt;
= Encrypting messages with your badge =&lt;br /&gt;
&lt;br /&gt;
Placeholder text.&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_MQTT&amp;diff=1329</id>
		<title>Swagbadge2021 MQTT</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_MQTT&amp;diff=1329"/>
		<updated>2021-01-23T21:19:05Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Receiving a message and taking action */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= About MQTT = &lt;br /&gt;
&lt;br /&gt;
MQTT is a lightweight message platform that uses individual topics (like a slack channel) that people can send messages to (called publishing) or listen for messages on (called subscribing).&lt;br /&gt;
&lt;br /&gt;
MQTT is designed for use on IoT devices. Check out [https://en.wikipedia.org/wiki/MQTT Wikipedia] for some background or [https://mqtt.org/ mqtt.org] for more information on it generally.&lt;br /&gt;
&lt;br /&gt;
== About the LCA Swagbadge MQTT server ==&lt;br /&gt;
&lt;br /&gt;
The badges have MQTT configured to talk to a dedicated server hosted by Andy Gelme, one of the OHMC organisers. We have done this for security and privacy reasons, and because it gives us an Australian server so it&#039;s faster.&lt;br /&gt;
&lt;br /&gt;
This server is at &amp;lt;code&amp;gt;101.181.46.180&amp;lt;/code&amp;gt;, the configuration for which is held on the badge at [https://github.com/geekscape/aiko_engine_mp/blob/master/configuration/mqtt.py configuration/mqtt.py]. The server has some special features:&lt;br /&gt;
* The &#039;&#039;upgrade/&#039;&#039; topic path prefix is public read: only Jon and Andy can update it.&lt;br /&gt;
* The &#039;&#039;aiko/&#039;&#039; topic path prefix is public read/write&lt;br /&gt;
* The &#039;&#039;public/&#039;&#039; topic path prefix is available for everyone to read/write&lt;br /&gt;
* The &#039;&#039;secret/&#039;&#039; topic path prefix is write-only&lt;br /&gt;
* We have some server monitoring to look for things snooping for all the channels, or who aren&#039;t using aiko/on a badge, and mitigations in the event a badge goes beserk and starts a spamming DOS attack.&lt;br /&gt;
&lt;br /&gt;
You are welcome to change which MQTT server your badge uses, by updating the mqtt.py configuration file. Some publicly hosted alternatives are provided (commented out) in the config.&lt;br /&gt;
&lt;br /&gt;
= Controlling your badge over MQTT =&lt;br /&gt;
&lt;br /&gt;
== Making your badge perform ==&lt;br /&gt;
&lt;br /&gt;
The easiest thing to do is send messages to show up on your screens.&lt;br /&gt;
&lt;br /&gt;
# Install an mqtt client on your machine&lt;br /&gt;
# Connect to the mqtt server (if you forget what it is, the IP address is shown on bootup)&lt;br /&gt;
# Using your badge&#039;s topic (public/esp32_your_badge_id/0/in) send it a message&lt;br /&gt;
&lt;br /&gt;
Messages are usually in the form of &amp;lt;code&amp;gt;(component:command arguments)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
mosquitto_sub -h 101.181.46.180 -t public/esp32_id/0 &amp;amp;   &amp;lt;&amp;lt; does this receive anything?&lt;br /&gt;
&lt;br /&gt;
mosquitto_pub -h 101.181.46.180 -t public/esp32_id/0/in -m &amp;quot;(oled:clear)&amp;quot;  &lt;br /&gt;
&lt;br /&gt;
mosquitto_pub -h 101.181.46.180 -t public/esp32_id/0/in -m &amp;quot;(oled:pixel 64 32)&amp;quot;  &lt;br /&gt;
&lt;br /&gt;
mosquitto_pub -h 101.181.46.180 -t public/esp32_id/0/in -m &amp;quot;(oled:text 0 50 Hello World)&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== OLED messages ===&lt;br /&gt;
;(oled&amp;amp;#58;clear)&lt;br /&gt;
: clears both screens&lt;br /&gt;
;(oled&amp;amp;#58;log Hello World!)&lt;br /&gt;
: writes a message along the bottom of the screens, scrolling up whatever is there out of the way&lt;br /&gt;
; (oled&amp;amp;#58;pixel x y)&lt;br /&gt;
: lights a pixel at that spot&lt;br /&gt;
; (oled&amp;amp;#58;text x y This is a test !)&lt;br /&gt;
: Puts some text at the position x,y. It will be displayed over the top of whatever&#039;s there.&lt;br /&gt;
&lt;br /&gt;
If you&#039;d like to make your application MQTT aware, take a look at the [https://github.com/geekscape/aiko_engine_mp/blob/master/lib/aiko/oled.py oled code].&lt;br /&gt;
&lt;br /&gt;
= Using MQTT on your badge =&lt;br /&gt;
&lt;br /&gt;
== Over Aiko ==&lt;br /&gt;
&lt;br /&gt;
Aiko has some convenience handlers to make using MQTT easier.&lt;br /&gt;
&lt;br /&gt;
Behind the scenes, Aiko routes messages to the specific handlers matching a given topic and supports multiple handlers “listening” to various specific topics.  There is an exception handler wrapped around every message handler, so that the overall MQTT thread doesn’t fail. &lt;br /&gt;
&lt;br /&gt;
=== Receiving a message and taking action ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Subscribe to a topic&#039;&#039;&#039;&lt;br /&gt;
Update &#039;&#039;configuration/mqtt.py&#039;&#039; and add in the topic to the &amp;lt;code&amp;gt;topic_subscribe&amp;lt;/code&amp;gt; list&lt;br /&gt;
    &amp;quot;topic_subscribe&amp;quot;: [ &amp;quot;$me/in&amp;quot;, &amp;quot;$me/exec&amp;quot;, upgrade_topic, &amp;quot;YOUR_TOPIC&amp;quot; ],&lt;br /&gt;
&lt;br /&gt;
If you want to listen/subscribe to all sub-topics, use a &amp;lt;code&amp;gt;#&amp;lt;/code&amp;gt; at the end. For example &amp;lt;code&amp;gt;public/chocolate/#&amp;lt;/code&amp;gt; will listen to public/chocolate and public/chocolate/lindt and public/chocolate/kokoblack and public/chocolate/ganache&lt;br /&gt;
&lt;br /&gt;
See https://github.com/geekscape/aiko_engine_mp/blob/master/configuration/mqtt.py#L13 as well as line 132 and 63&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Handle messages on that topic&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Define a message handler function, which takes a topic argument (in case you use the same message handler for multiple topics), and the payload (the message that was seen)&lt;br /&gt;
     def on_message(topic, payload_in):&lt;br /&gt;
        print(topic + &amp;quot;: &amp;quot; + payload_in)&lt;br /&gt;
&lt;br /&gt;
Add this handler function to the MQTT client: this is typically done in your application&#039;s initialise() method.&lt;br /&gt;
    mqtt.add_message_handler(on_message, &amp;quot;YOUR_TOPIC&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example code&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Here is a complete application example … https://github.com/geekscape/aiko_engine_mp/blob/master/applications/step_controller.py&lt;br /&gt;
&lt;br /&gt;
In this case, Aiko’s general MQTT on_message() handler will route all incoming messages to the specific handlers matching a given topic and supports multiple handlers “listening” to various specific topics.  There is an exception handler wrapped around every message handler … so that the MQTT thread doesn’t fail.  And over time Aiko’s error handling will improve, e.g re-subscribe to all MQTT topics on reconnection, etc.  At some point, Aiko will provide the heavy lifting for encrypted message publish / subscribe.  Finally, once Aiko Services (a general purpose distributed / embedded system) is released, then our ESP32 devices can become first-class citizens of a broader distributed service-based network (perhaps a month or so away).  Aiko also supports some “dangerous” fun, like opt-in enabling receiving microPython code as an MQTT message and executing it (obviously this is dangerous)&lt;br /&gt;
&lt;br /&gt;
=== Publishing a message ===&lt;br /&gt;
&lt;br /&gt;
Use the aiko mqtt client object to send a message.&lt;br /&gt;
&lt;br /&gt;
   from aiko.mqtt import client&lt;br /&gt;
   client.publish(topic, message)&lt;br /&gt;
&lt;br /&gt;
Which topic to use? On our LCA server, we are constrained to only use the &#039;public&#039; and &#039;aiko&#039; prefixed topics.&lt;br /&gt;
&lt;br /&gt;
To keep things neat and orderly, we recommend using&lt;br /&gt;
;public/esp32_SERIAL_ID/YOUR_TOPIC_HERE: for topics specific to your personal swagbadge&lt;br /&gt;
;public/SUBJECT/YOUR_TOPIC_HERE: for topics intended to share information with multiple swagbadges&lt;br /&gt;
&lt;br /&gt;
== Going direct to MQTT ==&lt;br /&gt;
&lt;br /&gt;
Since Aiko already makes an MQTT connection (to our server), you don’t need to make another MQTT connect, unless you want to interact with multiple MQTT servers (beyond the MQTT server already configured in &#039;&#039;configuration/mqtt.py&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
You can use the Aiko MQTT client object reference to access any of the MQTT library functions …&lt;br /&gt;
   &amp;gt;&amp;gt;&amp;gt; import aiko.mqtt.client as mqttclient&lt;br /&gt;
   &amp;gt;&amp;gt;&amp;gt; help(aiko.mqtt.client)&lt;br /&gt;
&lt;br /&gt;
[https://github.com/geekscape/aiko_engine_mp/blob/master/lib/umqtt/simple.py All of the available MQTT Client functions]&lt;br /&gt;
&lt;br /&gt;
= Encrypting messages with your badge =&lt;br /&gt;
&lt;br /&gt;
Placeholder text.&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1328</id>
		<title>Swagbadge2021 GettingStarted</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1328"/>
		<updated>2021-01-23T20:59:50Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Using Hardware SPI for a device like SSD1331 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Getting started with the Swagbadge =&lt;br /&gt;
&lt;br /&gt;
== Support ==&lt;br /&gt;
* The [https://spectrum.chat/lca2021-swagbadge Swag Badge Spectrum chat] is a place where the badge team hangs out, ready to answer your questions.&lt;br /&gt;
&lt;br /&gt;
== My package arrived in the mail, first steps. ==&lt;br /&gt;
* Your package should contain your badge, and some other goodies! &lt;br /&gt;
** [[File:swagbadgepackage.jpg|400px|alt=Image showing the contents of the swagbag package]]&lt;br /&gt;
** Badge&lt;br /&gt;
** SAO headers (x 4)&lt;br /&gt;
** SAO proto boards (x 2)&lt;br /&gt;
** SAO tux board&lt;br /&gt;
** Lanyard&lt;br /&gt;
** Stickers&lt;br /&gt;
** Instructions&lt;br /&gt;
* Take off the protective cases to reveal the screens.&lt;br /&gt;
* Powering it up&lt;br /&gt;
** Insert a micro USB cable into the badge and connect the other end to a USB port on your computer or USB power source.&lt;br /&gt;
** A green light should glow on the rear of the board, and a title appear across the two screens.&lt;br /&gt;
* Turning it on and off again&lt;br /&gt;
** Plugging/unplugging it is fine. Usually the badge isn&#039;t running anything intensely enough that just unpowering it would cause a problem.&lt;br /&gt;
* On bootup, you should see:&lt;br /&gt;
** The OLED screens will display &amp;quot;Aiko&amp;quot; and a version number as a title&lt;br /&gt;
** It will also display something else to tell you to set up your wifi.&lt;br /&gt;
&lt;br /&gt;
== Getting it on your network ==&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - wireless ===&lt;br /&gt;
&lt;br /&gt;
The first time you boot your badge, it won&#039;t know how to talk to your wifi network, so it creates its own temporary wifi network for you to connect to, so you can configure it.&lt;br /&gt;
&lt;br /&gt;
* Start your badge by plugging it in.&lt;br /&gt;
* The screens on your badge will say &amp;lt;code&amp;gt;Configure WiFi:&amp;lt;/code&amp;gt; &lt;br /&gt;
   [[File:configurewifi-1.png|300px]]&lt;br /&gt;
* Use your phone (or computer) to change wifi networks to use the badge. The badge wifi name starts with &amp;lt;code&amp;gt;aiko&amp;lt;/code&amp;gt; followed by some numbers/letters. &lt;br /&gt;
   [[File:configurewifi-2.png|200px]] -&amp;gt; [[File:configurewifi-3.png|200px]]&lt;br /&gt;
* Once you&#039;re connected to the badge wifi, open a web browser on that device to the IP address shown on the screens. Something like &amp;lt;code&amp;gt;http://192.168.4.1&amp;lt;/code&amp;gt; &lt;br /&gt;
   [[File:configurewifi-5.png|300px]]&lt;br /&gt;
* You&#039;ll be prompted to enter your wifi SSID and wifi password. &#039;&#039;&#039;Note: Your device can only use a 2.4GHz network&#039;&#039;&#039;: it is not compatible with 5GHz WiFi.&lt;br /&gt;
* The badge will restart using the credentials you&#039;ve provided and it will shut down its wifi access point. &lt;br /&gt;
   [[File:configurewifi-4.png|300px]]&lt;br /&gt;
* Your phone/computer will go back to using its usual wifi network and badge is now online!&lt;br /&gt;
&lt;br /&gt;
Note: If you are using an Android device to link the badge to your WiFi, it will pop up a dialog to say you are switching to a network that doesn&#039;t have Internet access and ask if you want to switch back. Select &amp;quot;Keep&amp;quot; to stay on the badge&#039;s temporary access point.&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - commandline with mpfshell ===&lt;br /&gt;
&lt;br /&gt;
If the above guide to setting up via the wifi AP (access point) doesn&#039;t work, you can put a configuration file onto the badge. You&#039;ll need a Python environment to do so, which you&#039;ll need anyway if you plan on writing your own badge software applications.&lt;br /&gt;
&lt;br /&gt;
* Start by getting [[Swagbadge2021_UpdatingSoftware|a copy of the aiko firmware, and installing mpfshell]]&lt;br /&gt;
* &#039;&#039;Note: Your device can only talk to a 2.4GHz network: it is not compatible with 5GHz.&#039;&#039;&lt;br /&gt;
* Edit aiko_engine_mp/configuration/net.py and insert the details of your SSID and password.&lt;br /&gt;
* use mpfshell: &amp;lt;code&amp;gt;mpfshell -o COM3&amp;lt;/code&amp;gt; (substitute the com port/tty of your badge)&lt;br /&gt;
* &amp;lt;code&amp;gt;put configuration/net.py configuration/net.py&amp;lt;/code&amp;gt;&lt;br /&gt;
* fire up repl to view the console log &lt;br /&gt;
* You can now restart your device&lt;br /&gt;
* On bootup it should now talk to your network and you can see it on the console log.&lt;br /&gt;
&lt;br /&gt;
Your badge will display its connection status on the screens.&lt;br /&gt;
&lt;br /&gt;
= Running pre-installed applications =&lt;br /&gt;
&lt;br /&gt;
== Aiko&#039;s minimal Swagbadge application ==&lt;br /&gt;
At the moment the badge by default a basic &amp;quot;Swagbadge&amp;quot; application within the Aiko framework. This application&lt;br /&gt;
* has a thread to keep wifi running, &lt;br /&gt;
* has a thread to stay connected to (our Australian, private) mqtt server&lt;br /&gt;
* has a thread to display a rotating header across the two oleds.&lt;br /&gt;
&lt;br /&gt;
You can now talk to your badge [[Swagbadge2021_MQTT|using MQTT messages]].&lt;br /&gt;
&lt;br /&gt;
== Running other applications ==&lt;br /&gt;
At the moment, &amp;quot;swagbadge&amp;quot; is the only application that&#039;s for use with the badge. &lt;br /&gt;
&lt;br /&gt;
There are [https://github.com/geekscape/aiko_engine_mp/tree/master/applications other applications] in the repo which are for other places the Aiko framework has been used.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve written an application of your own and want to run that by default on badge startup, &lt;br /&gt;
# edit your local copy of configuration/main.py and change the value of the &amp;quot;application&amp;quot; to point to your new application.&lt;br /&gt;
# using mpfshell, &#039;put&#039; configuration/main.py and applications/your_application.py onto the badge&lt;br /&gt;
# Restart the badge&lt;br /&gt;
&lt;br /&gt;
== Running example code ==&lt;br /&gt;
There is [https://github.com/geekscape/aiko_engine_mp/tree/master/examples example code] which has a number of examples in it, including a snake game and a demo of how to use various badge functions.&lt;br /&gt;
&lt;br /&gt;
# From your commandline on your computer, use mpfshell to put whatever example code you want onto the badge.&lt;br /&gt;
# To run example code, you can use the &amp;quot;emergency stop&amp;quot; function to halt any other applications and put you in the repl.&lt;br /&gt;
## Touch both of the bottom spots on the sliders&lt;br /&gt;
## Reboot the badge&lt;br /&gt;
# Now at the repl prompt, type (replace the name of the module as appropriate for the code you want to run): &lt;br /&gt;
&lt;br /&gt;
Use examples.game_snake as example:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
from examples.game_snake import run&lt;br /&gt;
run()&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ctrl-c to halt operation and return to the repl prompt.&lt;br /&gt;
&lt;br /&gt;
= Hardware pinout =&lt;br /&gt;
&lt;br /&gt;
You can get the schematic and pin mapping on this page: https://github.com/CCHS-Melbourne/Swag-Badge/blob/master/swag-badge-schematic.pdf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- GPIO0 : left breakout pin4&lt;br /&gt;
- GPIO2 : left breakout pin3&lt;br /&gt;
&lt;br /&gt;
- GPIO4 : SCL (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO5 : SDA (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO12/15: slider #1&lt;br /&gt;
- GPIO13: left breakout pin3&lt;br /&gt;
- GPIO14/27: slider #2&lt;br /&gt;
- GPIO16: left switch  (under screen #1)&lt;br /&gt;
- GPIO17: right switch (under screen #2)&lt;br /&gt;
&lt;br /&gt;
- GPIO18: SAO3 pin3 + LB pin7&lt;br /&gt;
- GPIO23: SAO3 pin4&lt;br /&gt;
&lt;br /&gt;
- GPIO19: SAO1 pin4&lt;br /&gt;
- GPIO22: SAO1 pin3 (also onboard blue LED in the back)&lt;br /&gt;
&lt;br /&gt;
- GPIO21: unused but not wired on this chip&lt;br /&gt;
&lt;br /&gt;
- GPIO25: SAO4 pin4 + RB pin6&lt;br /&gt;
- GPIO26: SAO4 pin3 + RB pin7&lt;br /&gt;
&lt;br /&gt;
- GPIO27: free (pin available on the chip, not routed anywhere)&lt;br /&gt;
&lt;br /&gt;
- GPIO32: SAO2 pin3 + RB pin4 (touch pin, can be used with SAO tux foot or nose touchpad) &lt;br /&gt;
- GPIO33: SAO2 pin4 + RB pin5 (touch pin, can be used with SAO tux foot or nose touchpad)&lt;br /&gt;
&lt;br /&gt;
- GPIO34: right breakout pin2 (input only)&lt;br /&gt;
- GPIO35: right breakout pin3 (input only)&lt;br /&gt;
&lt;br /&gt;
- GPIO36: unused but not wired on this chip (input only)&lt;br /&gt;
- GPIO39: unused but not wired on this chip (input only)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Hardware SPI for a device like SSD1331 ==&lt;br /&gt;
ESP32 has 2 DMA capable hardware SPI busses usable by the user: SPI2/HSPI and SPI3/VSPI (see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/spi_master.html and https://github.com/espressif/arduino-esp32/blob/master/libraries/SPI/examples/SPI_Multiple_Buses/SPI_Multiple_Buses.ino for how to use them at the same time ). The important note in the espressif doc is that if you do not use the dedicated default HWSPI pins, they get routed through a hardware MUX and your maximum SPI speed is lowered from 80Mhz to 40Mhz.&lt;br /&gt;
&lt;br /&gt;
If you would like to connect an SPI device like an SSD1331 96x64 color TFT, here are default hardware pin numbers, and pins you can use for non SPI signals (RES/RST, DC/A0/RS, and CS/SS):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  SD1331 Pin	        ESP32	ESP32&lt;br /&gt;
1 GND                   VSPI    HSPI &lt;br /&gt;
2 VCC&lt;br /&gt;
3 SCL/SCK/CLK/D0	18	14   &lt;br /&gt;
4 SDA/SDI/MOSI/D1	23	13   &lt;br /&gt;
---- 2 pins above and MISO are HWSPI, pins below are anything&lt;br /&gt;
---- RST is not part of SPI, it&#039;s an out of band signal to reset a TFT&lt;br /&gt;
---- This could be wired to the ESP32 EN(reset) pin&lt;br /&gt;
5 RES/RST		26	26   &lt;br /&gt;
---- Data/Command pin is not part of SPI but used to tell the TFT if incoming SPI&lt;br /&gt;
---- data is actually a command, or pixel data.&lt;br /&gt;
6 DC/A0/RS (data)	25	25   &lt;br /&gt;
---- Cable select chooses which SPI device we&#039;re talking to, if there is only&lt;br /&gt;
---- one, it can be tied to ground. Any pin is fine&lt;br /&gt;
7 CS/SS =&amp;gt; GND	        27	15   &lt;br /&gt;
&lt;br /&gt;
---- MISO is not used to talk to TFTs, and is a hardware pin, but unused here&lt;br /&gt;
  MISO		        19	12    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
pins 12/13/14 are already used by the badge, but 18/19/23 are usable (SAO3 and SAO1), and since MISO is unused, you could also assign it to GPIO21 which isn&#039;t wired at all on the lolin lite chip.  &lt;br /&gt;
If you&#039;d also like to keep SAO4 usable (25/26), you can wire CS/SS to ground, move DC/AO/RS to pin 27, and free up pin 26 (RST) by wiring RST to the ESP32 ENA pin, which should issue a TFT reset every time the ESP32 is reset.&lt;br /&gt;
&lt;br /&gt;
End result: https://youtu.be/TYItVAa4tJY&lt;br /&gt;
&lt;br /&gt;
= Extensions: Adding a SAO =&lt;br /&gt;
* provided by others&lt;br /&gt;
* build your own (linky here to our docs)&lt;br /&gt;
&lt;br /&gt;
= Extensions: Writing your own applications =&lt;br /&gt;
&lt;br /&gt;
Between when we ship the board and when it arrives, there might be some changes to the software framework (Aiko). Here&#039;s how to update it. Or perhaps you&#039;re interested in writing your own applications? &lt;br /&gt;
&lt;br /&gt;
* [[Swagbadge2021_UpdatingSoftware|Updating the Software]]&lt;br /&gt;
* [[Swagbadge2021_SoftwareDev|Writing your own badge programs]]&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1327</id>
		<title>Swagbadge2021 GettingStarted</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1327"/>
		<updated>2021-01-23T20:57:52Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Using Hardware SPI for a device like SSD1331 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Getting started with the Swagbadge =&lt;br /&gt;
&lt;br /&gt;
== Support ==&lt;br /&gt;
* The [https://spectrum.chat/lca2021-swagbadge Swag Badge Spectrum chat] is a place where the badge team hangs out, ready to answer your questions.&lt;br /&gt;
&lt;br /&gt;
== My package arrived in the mail, first steps. ==&lt;br /&gt;
* Your package should contain your badge, and some other goodies! &lt;br /&gt;
** [[File:swagbadgepackage.jpg|400px|alt=Image showing the contents of the swagbag package]]&lt;br /&gt;
** Badge&lt;br /&gt;
** SAO headers (x 4)&lt;br /&gt;
** SAO proto boards (x 2)&lt;br /&gt;
** SAO tux board&lt;br /&gt;
** Lanyard&lt;br /&gt;
** Stickers&lt;br /&gt;
** Instructions&lt;br /&gt;
* Take off the protective cases to reveal the screens.&lt;br /&gt;
* Powering it up&lt;br /&gt;
** Insert a micro USB cable into the badge and connect the other end to a USB port on your computer or USB power source.&lt;br /&gt;
** A green light should glow on the rear of the board, and a title appear across the two screens.&lt;br /&gt;
* Turning it on and off again&lt;br /&gt;
** Plugging/unplugging it is fine. Usually the badge isn&#039;t running anything intensely enough that just unpowering it would cause a problem.&lt;br /&gt;
* On bootup, you should see:&lt;br /&gt;
** The OLED screens will display &amp;quot;Aiko&amp;quot; and a version number as a title&lt;br /&gt;
** It will also display something else to tell you to set up your wifi.&lt;br /&gt;
&lt;br /&gt;
== Getting it on your network ==&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - wireless ===&lt;br /&gt;
&lt;br /&gt;
The first time you boot your badge, it won&#039;t know how to talk to your wifi network, so it creates its own temporary wifi network for you to connect to, so you can configure it.&lt;br /&gt;
&lt;br /&gt;
* Start your badge by plugging it in.&lt;br /&gt;
* The screens on your badge will say &amp;lt;code&amp;gt;Configure WiFi:&amp;lt;/code&amp;gt; &lt;br /&gt;
   [[File:configurewifi-1.png|300px]]&lt;br /&gt;
* Use your phone (or computer) to change wifi networks to use the badge. The badge wifi name starts with &amp;lt;code&amp;gt;aiko&amp;lt;/code&amp;gt; followed by some numbers/letters. &lt;br /&gt;
   [[File:configurewifi-2.png|200px]] -&amp;gt; [[File:configurewifi-3.png|200px]]&lt;br /&gt;
* Once you&#039;re connected to the badge wifi, open a web browser on that device to the IP address shown on the screens. Something like &amp;lt;code&amp;gt;http://192.168.4.1&amp;lt;/code&amp;gt; &lt;br /&gt;
   [[File:configurewifi-5.png|300px]]&lt;br /&gt;
* You&#039;ll be prompted to enter your wifi SSID and wifi password. &#039;&#039;&#039;Note: Your device can only use a 2.4GHz network&#039;&#039;&#039;: it is not compatible with 5GHz WiFi.&lt;br /&gt;
* The badge will restart using the credentials you&#039;ve provided and it will shut down its wifi access point. &lt;br /&gt;
   [[File:configurewifi-4.png|300px]]&lt;br /&gt;
* Your phone/computer will go back to using its usual wifi network and badge is now online!&lt;br /&gt;
&lt;br /&gt;
Note: If you are using an Android device to link the badge to your WiFi, it will pop up a dialog to say you are switching to a network that doesn&#039;t have Internet access and ask if you want to switch back. Select &amp;quot;Keep&amp;quot; to stay on the badge&#039;s temporary access point.&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - commandline with mpfshell ===&lt;br /&gt;
&lt;br /&gt;
If the above guide to setting up via the wifi AP (access point) doesn&#039;t work, you can put a configuration file onto the badge. You&#039;ll need a Python environment to do so, which you&#039;ll need anyway if you plan on writing your own badge software applications.&lt;br /&gt;
&lt;br /&gt;
* Start by getting [[Swagbadge2021_UpdatingSoftware|a copy of the aiko firmware, and installing mpfshell]]&lt;br /&gt;
* &#039;&#039;Note: Your device can only talk to a 2.4GHz network: it is not compatible with 5GHz.&#039;&#039;&lt;br /&gt;
* Edit aiko_engine_mp/configuration/net.py and insert the details of your SSID and password.&lt;br /&gt;
* use mpfshell: &amp;lt;code&amp;gt;mpfshell -o COM3&amp;lt;/code&amp;gt; (substitute the com port/tty of your badge)&lt;br /&gt;
* &amp;lt;code&amp;gt;put configuration/net.py configuration/net.py&amp;lt;/code&amp;gt;&lt;br /&gt;
* fire up repl to view the console log &lt;br /&gt;
* You can now restart your device&lt;br /&gt;
* On bootup it should now talk to your network and you can see it on the console log.&lt;br /&gt;
&lt;br /&gt;
Your badge will display its connection status on the screens.&lt;br /&gt;
&lt;br /&gt;
= Running pre-installed applications =&lt;br /&gt;
&lt;br /&gt;
== Aiko&#039;s minimal Swagbadge application ==&lt;br /&gt;
At the moment the badge by default a basic &amp;quot;Swagbadge&amp;quot; application within the Aiko framework. This application&lt;br /&gt;
* has a thread to keep wifi running, &lt;br /&gt;
* has a thread to stay connected to (our Australian, private) mqtt server&lt;br /&gt;
* has a thread to display a rotating header across the two oleds.&lt;br /&gt;
&lt;br /&gt;
You can now talk to your badge [[Swagbadge2021_MQTT|using MQTT messages]].&lt;br /&gt;
&lt;br /&gt;
== Running other applications ==&lt;br /&gt;
At the moment, &amp;quot;swagbadge&amp;quot; is the only application that&#039;s for use with the badge. &lt;br /&gt;
&lt;br /&gt;
There are [https://github.com/geekscape/aiko_engine_mp/tree/master/applications other applications] in the repo which are for other places the Aiko framework has been used.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve written an application of your own and want to run that by default on badge startup, &lt;br /&gt;
# edit your local copy of configuration/main.py and change the value of the &amp;quot;application&amp;quot; to point to your new application.&lt;br /&gt;
# using mpfshell, &#039;put&#039; configuration/main.py and applications/your_application.py onto the badge&lt;br /&gt;
# Restart the badge&lt;br /&gt;
&lt;br /&gt;
== Running example code ==&lt;br /&gt;
There is [https://github.com/geekscape/aiko_engine_mp/tree/master/examples example code] which has a number of examples in it, including a snake game and a demo of how to use various badge functions.&lt;br /&gt;
&lt;br /&gt;
# From your commandline on your computer, use mpfshell to put whatever example code you want onto the badge.&lt;br /&gt;
# To run example code, you can use the &amp;quot;emergency stop&amp;quot; function to halt any other applications and put you in the repl.&lt;br /&gt;
## Touch both of the bottom spots on the sliders&lt;br /&gt;
## Reboot the badge&lt;br /&gt;
# Now at the repl prompt, type (replace the name of the module as appropriate for the code you want to run): &lt;br /&gt;
&lt;br /&gt;
Use examples.game_snake as example:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
from examples.game_snake import run&lt;br /&gt;
run()&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ctrl-c to halt operation and return to the repl prompt.&lt;br /&gt;
&lt;br /&gt;
= Hardware pinout =&lt;br /&gt;
&lt;br /&gt;
You can get the schematic and pin mapping on this page: https://github.com/CCHS-Melbourne/Swag-Badge/blob/master/swag-badge-schematic.pdf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- GPIO0 : left breakout pin4&lt;br /&gt;
- GPIO2 : left breakout pin3&lt;br /&gt;
&lt;br /&gt;
- GPIO4 : SCL (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO5 : SDA (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO12/15: slider #1&lt;br /&gt;
- GPIO13: left breakout pin3&lt;br /&gt;
- GPIO14/27: slider #2&lt;br /&gt;
- GPIO16: left switch  (under screen #1)&lt;br /&gt;
- GPIO17: right switch (under screen #2)&lt;br /&gt;
&lt;br /&gt;
- GPIO18: SAO3 pin3 + LB pin7&lt;br /&gt;
- GPIO23: SAO3 pin4&lt;br /&gt;
&lt;br /&gt;
- GPIO19: SAO1 pin4&lt;br /&gt;
- GPIO22: SAO1 pin3 (also onboard blue LED in the back)&lt;br /&gt;
&lt;br /&gt;
- GPIO21: unused but not wired on this chip&lt;br /&gt;
&lt;br /&gt;
- GPIO25: SAO4 pin4 + RB pin6&lt;br /&gt;
- GPIO26: SAO4 pin3 + RB pin7&lt;br /&gt;
&lt;br /&gt;
- GPIO27: free (pin available on the chip, not routed anywhere)&lt;br /&gt;
&lt;br /&gt;
- GPIO32: SAO2 pin3 + RB pin4 (touch pin, can be used with SAO tux foot or nose touchpad) &lt;br /&gt;
- GPIO33: SAO2 pin4 + RB pin5 (touch pin, can be used with SAO tux foot or nose touchpad)&lt;br /&gt;
&lt;br /&gt;
- GPIO34: right breakout pin2 (input only)&lt;br /&gt;
- GPIO35: right breakout pin3 (input only)&lt;br /&gt;
&lt;br /&gt;
- GPIO36: unused but not wired on this chip (input only)&lt;br /&gt;
- GPIO39: unused but not wired on this chip (input only)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Hardware SPI for a device like SSD1331 ==&lt;br /&gt;
ESP32 has 2 DMA capable hardware SPI busses usable by the user: SPI2/HSPI and SPI3/VSPI (see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/spi_master.html and https://github.com/espressif/arduino-esp32/blob/master/libraries/SPI/examples/SPI_Multiple_Buses/SPI_Multiple_Buses.ino for how to use them at the same time ). The important note in the espressif doc is that if you do not use the dedicated default HWSPI pins, they get routed through a hardware MUX and your maximum SPI speed is lowered from 80Mhz to 40Mhz.&lt;br /&gt;
&lt;br /&gt;
If you would like to connect an SPI device like an SSD1331 96x64 color TFT, here are default hardware pin numbers, and pins you can use for non SPI signals (RES/RST, DC/A0/RS, and CS/SS):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  SD1331 Pin	        ESP32	ESP32&lt;br /&gt;
1 GND                   VSPI    HSPI &lt;br /&gt;
2 VCC&lt;br /&gt;
3 SCL/SCK/CLK/D0	18	14   &lt;br /&gt;
4 SDA/SDI/MOSI/D1	23	13   &lt;br /&gt;
---- 2 pins above and MISO are HWSPI, pins below are anything&lt;br /&gt;
---- RST is not part of SPI, it&#039;s an out of band signal to reset a TFT&lt;br /&gt;
---- This could be wired to the ESP32 EN(reset) pin&lt;br /&gt;
5 RES/RST		26	26   &lt;br /&gt;
---- Data/Command pin is not part of SPI but used to tell the TFT if incoming SPI&lt;br /&gt;
---- data is actually a command, or pixel data.&lt;br /&gt;
6 DC/A0/RS (data)	25	25   &lt;br /&gt;
---- Cable select chooses which SPI device we&#039;re talking to, if there is only&lt;br /&gt;
---- one, it can be tied to ground. Any pin is fine&lt;br /&gt;
7 CS/SS =&amp;gt; GND	        27	15   &lt;br /&gt;
&lt;br /&gt;
---- MISO is not used to talk to TFTs, and is a hardware pin, but unused here&lt;br /&gt;
  MISO		        19	12    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
pins 12/13/14 are already used by the badge, but 18/19/23 are usable (SAO3 and SAO1), and since MISO is unused, you could also assign it to GPIO21 which isn&#039;t wired at all on the lolin lite chip.  &lt;br /&gt;
If you&#039;d also like to keep SAO4 usable (25/26), you can wire CS/SS to ground, move DC/AO/RS to pin 27, and free up pin 26 (RST) by wiring RST to the ESP32 ENA pin, which should issue a TFT reset every time the ESP32 is reset.&lt;br /&gt;
&lt;br /&gt;
= Extensions: Adding a SAO =&lt;br /&gt;
* provided by others&lt;br /&gt;
* build your own (linky here to our docs)&lt;br /&gt;
&lt;br /&gt;
= Extensions: Writing your own applications =&lt;br /&gt;
&lt;br /&gt;
Between when we ship the board and when it arrives, there might be some changes to the software framework (Aiko). Here&#039;s how to update it. Or perhaps you&#039;re interested in writing your own applications? &lt;br /&gt;
&lt;br /&gt;
* [[Swagbadge2021_UpdatingSoftware|Updating the Software]]&lt;br /&gt;
* [[Swagbadge2021_SoftwareDev|Writing your own badge programs]]&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1326</id>
		<title>Swagbadge2021 GettingStarted</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1326"/>
		<updated>2021-01-23T20:57:00Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Using Hardware SPI for a device like SSD1331 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Getting started with the Swagbadge =&lt;br /&gt;
&lt;br /&gt;
== Support ==&lt;br /&gt;
* The [https://spectrum.chat/lca2021-swagbadge Swag Badge Spectrum chat] is a place where the badge team hangs out, ready to answer your questions.&lt;br /&gt;
&lt;br /&gt;
== My package arrived in the mail, first steps. ==&lt;br /&gt;
* Your package should contain your badge, and some other goodies! &lt;br /&gt;
** [[File:swagbadgepackage.jpg|400px|alt=Image showing the contents of the swagbag package]]&lt;br /&gt;
** Badge&lt;br /&gt;
** SAO headers (x 4)&lt;br /&gt;
** SAO proto boards (x 2)&lt;br /&gt;
** SAO tux board&lt;br /&gt;
** Lanyard&lt;br /&gt;
** Stickers&lt;br /&gt;
** Instructions&lt;br /&gt;
* Take off the protective cases to reveal the screens.&lt;br /&gt;
* Powering it up&lt;br /&gt;
** Insert a micro USB cable into the badge and connect the other end to a USB port on your computer or USB power source.&lt;br /&gt;
** A green light should glow on the rear of the board, and a title appear across the two screens.&lt;br /&gt;
* Turning it on and off again&lt;br /&gt;
** Plugging/unplugging it is fine. Usually the badge isn&#039;t running anything intensely enough that just unpowering it would cause a problem.&lt;br /&gt;
* On bootup, you should see:&lt;br /&gt;
** The OLED screens will display &amp;quot;Aiko&amp;quot; and a version number as a title&lt;br /&gt;
** It will also display something else to tell you to set up your wifi.&lt;br /&gt;
&lt;br /&gt;
== Getting it on your network ==&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - wireless ===&lt;br /&gt;
&lt;br /&gt;
The first time you boot your badge, it won&#039;t know how to talk to your wifi network, so it creates its own temporary wifi network for you to connect to, so you can configure it.&lt;br /&gt;
&lt;br /&gt;
* Start your badge by plugging it in.&lt;br /&gt;
* The screens on your badge will say &amp;lt;code&amp;gt;Configure WiFi:&amp;lt;/code&amp;gt; &lt;br /&gt;
   [[File:configurewifi-1.png|300px]]&lt;br /&gt;
* Use your phone (or computer) to change wifi networks to use the badge. The badge wifi name starts with &amp;lt;code&amp;gt;aiko&amp;lt;/code&amp;gt; followed by some numbers/letters. &lt;br /&gt;
   [[File:configurewifi-2.png|200px]] -&amp;gt; [[File:configurewifi-3.png|200px]]&lt;br /&gt;
* Once you&#039;re connected to the badge wifi, open a web browser on that device to the IP address shown on the screens. Something like &amp;lt;code&amp;gt;http://192.168.4.1&amp;lt;/code&amp;gt; &lt;br /&gt;
   [[File:configurewifi-5.png|300px]]&lt;br /&gt;
* You&#039;ll be prompted to enter your wifi SSID and wifi password. &#039;&#039;&#039;Note: Your device can only use a 2.4GHz network&#039;&#039;&#039;: it is not compatible with 5GHz WiFi.&lt;br /&gt;
* The badge will restart using the credentials you&#039;ve provided and it will shut down its wifi access point. &lt;br /&gt;
   [[File:configurewifi-4.png|300px]]&lt;br /&gt;
* Your phone/computer will go back to using its usual wifi network and badge is now online!&lt;br /&gt;
&lt;br /&gt;
Note: If you are using an Android device to link the badge to your WiFi, it will pop up a dialog to say you are switching to a network that doesn&#039;t have Internet access and ask if you want to switch back. Select &amp;quot;Keep&amp;quot; to stay on the badge&#039;s temporary access point.&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - commandline with mpfshell ===&lt;br /&gt;
&lt;br /&gt;
If the above guide to setting up via the wifi AP (access point) doesn&#039;t work, you can put a configuration file onto the badge. You&#039;ll need a Python environment to do so, which you&#039;ll need anyway if you plan on writing your own badge software applications.&lt;br /&gt;
&lt;br /&gt;
* Start by getting [[Swagbadge2021_UpdatingSoftware|a copy of the aiko firmware, and installing mpfshell]]&lt;br /&gt;
* &#039;&#039;Note: Your device can only talk to a 2.4GHz network: it is not compatible with 5GHz.&#039;&#039;&lt;br /&gt;
* Edit aiko_engine_mp/configuration/net.py and insert the details of your SSID and password.&lt;br /&gt;
* use mpfshell: &amp;lt;code&amp;gt;mpfshell -o COM3&amp;lt;/code&amp;gt; (substitute the com port/tty of your badge)&lt;br /&gt;
* &amp;lt;code&amp;gt;put configuration/net.py configuration/net.py&amp;lt;/code&amp;gt;&lt;br /&gt;
* fire up repl to view the console log &lt;br /&gt;
* You can now restart your device&lt;br /&gt;
* On bootup it should now talk to your network and you can see it on the console log.&lt;br /&gt;
&lt;br /&gt;
Your badge will display its connection status on the screens.&lt;br /&gt;
&lt;br /&gt;
= Running pre-installed applications =&lt;br /&gt;
&lt;br /&gt;
== Aiko&#039;s minimal Swagbadge application ==&lt;br /&gt;
At the moment the badge by default a basic &amp;quot;Swagbadge&amp;quot; application within the Aiko framework. This application&lt;br /&gt;
* has a thread to keep wifi running, &lt;br /&gt;
* has a thread to stay connected to (our Australian, private) mqtt server&lt;br /&gt;
* has a thread to display a rotating header across the two oleds.&lt;br /&gt;
&lt;br /&gt;
You can now talk to your badge [[Swagbadge2021_MQTT|using MQTT messages]].&lt;br /&gt;
&lt;br /&gt;
== Running other applications ==&lt;br /&gt;
At the moment, &amp;quot;swagbadge&amp;quot; is the only application that&#039;s for use with the badge. &lt;br /&gt;
&lt;br /&gt;
There are [https://github.com/geekscape/aiko_engine_mp/tree/master/applications other applications] in the repo which are for other places the Aiko framework has been used.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve written an application of your own and want to run that by default on badge startup, &lt;br /&gt;
# edit your local copy of configuration/main.py and change the value of the &amp;quot;application&amp;quot; to point to your new application.&lt;br /&gt;
# using mpfshell, &#039;put&#039; configuration/main.py and applications/your_application.py onto the badge&lt;br /&gt;
# Restart the badge&lt;br /&gt;
&lt;br /&gt;
== Running example code ==&lt;br /&gt;
There is [https://github.com/geekscape/aiko_engine_mp/tree/master/examples example code] which has a number of examples in it, including a snake game and a demo of how to use various badge functions.&lt;br /&gt;
&lt;br /&gt;
# From your commandline on your computer, use mpfshell to put whatever example code you want onto the badge.&lt;br /&gt;
# To run example code, you can use the &amp;quot;emergency stop&amp;quot; function to halt any other applications and put you in the repl.&lt;br /&gt;
## Touch both of the bottom spots on the sliders&lt;br /&gt;
## Reboot the badge&lt;br /&gt;
# Now at the repl prompt, type (replace the name of the module as appropriate for the code you want to run): &lt;br /&gt;
&lt;br /&gt;
Use examples.game_snake as example:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
from examples.game_snake import run&lt;br /&gt;
run()&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ctrl-c to halt operation and return to the repl prompt.&lt;br /&gt;
&lt;br /&gt;
= Hardware pinout =&lt;br /&gt;
&lt;br /&gt;
You can get the schematic and pin mapping on this page: https://github.com/CCHS-Melbourne/Swag-Badge/blob/master/swag-badge-schematic.pdf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- GPIO0 : left breakout pin4&lt;br /&gt;
- GPIO2 : left breakout pin3&lt;br /&gt;
&lt;br /&gt;
- GPIO4 : SCL (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO5 : SDA (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO12/15: slider #1&lt;br /&gt;
- GPIO13: left breakout pin3&lt;br /&gt;
- GPIO14/27: slider #2&lt;br /&gt;
- GPIO16: left switch  (under screen #1)&lt;br /&gt;
- GPIO17: right switch (under screen #2)&lt;br /&gt;
&lt;br /&gt;
- GPIO18: SAO3 pin3 + LB pin7&lt;br /&gt;
- GPIO23: SAO3 pin4&lt;br /&gt;
&lt;br /&gt;
- GPIO19: SAO1 pin4&lt;br /&gt;
- GPIO22: SAO1 pin3 (also onboard blue LED in the back)&lt;br /&gt;
&lt;br /&gt;
- GPIO21: unused but not wired on this chip&lt;br /&gt;
&lt;br /&gt;
- GPIO25: SAO4 pin4 + RB pin6&lt;br /&gt;
- GPIO26: SAO4 pin3 + RB pin7&lt;br /&gt;
&lt;br /&gt;
- GPIO27: free (pin available on the chip, not routed anywhere)&lt;br /&gt;
&lt;br /&gt;
- GPIO32: SAO2 pin3 + RB pin4 (touch pin, can be used with SAO tux foot or nose touchpad) &lt;br /&gt;
- GPIO33: SAO2 pin4 + RB pin5 (touch pin, can be used with SAO tux foot or nose touchpad)&lt;br /&gt;
&lt;br /&gt;
- GPIO34: right breakout pin2 (input only)&lt;br /&gt;
- GPIO35: right breakout pin3 (input only)&lt;br /&gt;
&lt;br /&gt;
- GPIO36: unused but not wired on this chip (input only)&lt;br /&gt;
- GPIO39: unused but not wired on this chip (input only)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Hardware SPI for a device like SSD1331 ==&lt;br /&gt;
ESP32 has 2 DMA capable hardware SPI busses usable by the user: SPI2/HSPI and SPI3/VSPI (see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/spi_master.html and https://github.com/espressif/arduino-esp32/blob/master/libraries/SPI/examples/SPI_Multiple_Buses/SPI_Multiple_Buses.ino for how to use them at the same time ). The important note in the espressif doc is that if you do not use the dedicated default HWSPI pins, they get routed through a hardware MUX and your maximum SPI speed is lowered from 80Mhz to 40Mhz.&lt;br /&gt;
&lt;br /&gt;
If you would like to connect an SPI device like an SSD1331 96x64 color TFT, here are default hardware pin numbers, and &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  SD1331 Pin	        ESP32	ESP32&lt;br /&gt;
1 GND                   VSPI    HSPI &lt;br /&gt;
2 VCC&lt;br /&gt;
3 SCL/SCK/CLK/D0	18	14   &lt;br /&gt;
4 SDA/SDI/MOSI/D1	23	13   &lt;br /&gt;
---- 2 pins above and MISO are HWSPI, pins below are anything&lt;br /&gt;
---- RST is not part of SPI, it&#039;s an out of band signal to reset a TFT&lt;br /&gt;
---- This could be wired to the ESP32 EN(reset) pin&lt;br /&gt;
5 RES/RST		26	26   &lt;br /&gt;
---- Data/Command pin is not part of SPI but used to tell the TFT if incoming SPI&lt;br /&gt;
---- data is actually a command, or pixel data.&lt;br /&gt;
6 DC/A0/RS (data)	25	25   &lt;br /&gt;
---- Cable select chooses which SPI device we&#039;re talking to, if there is only&lt;br /&gt;
---- one, it can be tied to ground. Any pin is fine&lt;br /&gt;
7 CS/SS =&amp;gt; GND	        27	15   &lt;br /&gt;
&lt;br /&gt;
---- MISO is not used to talk to TFTs, and is a hardware pin, but unused here&lt;br /&gt;
  MISO		        19	12    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
pins 12/13/14 are already used by the badge, but 18/19/23 are usable (SAO3 and SAO1), and since MISO is unused, you could also assign it to GPIO21 which isn&#039;t wired at all on the lolin lite chip.  &lt;br /&gt;
If you&#039;d also like to keep SAO4 usable (25/26), you can wire CS/SS to ground, move DC/AO/RS to pin 27, and free up pin 26 (RST) by wiring RST to the ESP32 ENA pin, which should issue a TFT reset every time the ESP32 is reset.&lt;br /&gt;
&lt;br /&gt;
= Extensions: Adding a SAO =&lt;br /&gt;
* provided by others&lt;br /&gt;
* build your own (linky here to our docs)&lt;br /&gt;
&lt;br /&gt;
= Extensions: Writing your own applications =&lt;br /&gt;
&lt;br /&gt;
Between when we ship the board and when it arrives, there might be some changes to the software framework (Aiko). Here&#039;s how to update it. Or perhaps you&#039;re interested in writing your own applications? &lt;br /&gt;
&lt;br /&gt;
* [[Swagbadge2021_UpdatingSoftware|Updating the Software]]&lt;br /&gt;
* [[Swagbadge2021_SoftwareDev|Writing your own badge programs]]&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1325</id>
		<title>Swagbadge2021 GettingStarted</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1325"/>
		<updated>2021-01-23T20:31:46Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Using Hardware SPI for a device like SSD1331 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Getting started with the Swagbadge =&lt;br /&gt;
&lt;br /&gt;
== Support ==&lt;br /&gt;
* The [https://spectrum.chat/lca2021-swagbadge Swag Badge Spectrum chat] is a place where the badge team hangs out, ready to answer your questions.&lt;br /&gt;
&lt;br /&gt;
== My package arrived in the mail, first steps. ==&lt;br /&gt;
* Your package should contain your badge, and some other goodies! &lt;br /&gt;
** [[File:swagbadgepackage.jpg|400px|alt=Image showing the contents of the swagbag package]]&lt;br /&gt;
** Badge&lt;br /&gt;
** SAO headers (x 4)&lt;br /&gt;
** SAO proto boards (x 2)&lt;br /&gt;
** SAO tux board&lt;br /&gt;
** Lanyard&lt;br /&gt;
** Stickers&lt;br /&gt;
** Instructions&lt;br /&gt;
* Take off the protective cases to reveal the screens.&lt;br /&gt;
* Powering it up&lt;br /&gt;
** Insert a micro USB cable into the badge and connect the other end to a USB port on your computer or USB power source.&lt;br /&gt;
** A green light should glow on the rear of the board, and a title appear across the two screens.&lt;br /&gt;
* Turning it on and off again&lt;br /&gt;
** Plugging/unplugging it is fine. Usually the badge isn&#039;t running anything intensely enough that just unpowering it would cause a problem.&lt;br /&gt;
* On bootup, you should see:&lt;br /&gt;
** The OLED screens will display &amp;quot;Aiko&amp;quot; and a version number as a title&lt;br /&gt;
** It will also display something else to tell you to set up your wifi.&lt;br /&gt;
&lt;br /&gt;
== Getting it on your network ==&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - wireless ===&lt;br /&gt;
&lt;br /&gt;
The first time you boot your badge, it won&#039;t know how to talk to your wifi network, so it creates its own temporary wifi network for you to connect to, so you can configure it.&lt;br /&gt;
&lt;br /&gt;
* Start your badge by plugging it in.&lt;br /&gt;
* The screens on your badge will say &amp;lt;code&amp;gt;Configure WiFi:&amp;lt;/code&amp;gt; &lt;br /&gt;
   [[File:configurewifi-1.png|300px]]&lt;br /&gt;
* Use your phone (or computer) to change wifi networks to use the badge. The badge wifi name starts with &amp;lt;code&amp;gt;aiko&amp;lt;/code&amp;gt; followed by some numbers/letters. &lt;br /&gt;
   [[File:configurewifi-2.png|200px]] -&amp;gt; [[File:configurewifi-3.png|200px]]&lt;br /&gt;
* Once you&#039;re connected to the badge wifi, open a web browser on that device to the IP address shown on the screens. Something like &amp;lt;code&amp;gt;http://192.168.4.1&amp;lt;/code&amp;gt; &lt;br /&gt;
   [[File:configurewifi-5.png|300px]]&lt;br /&gt;
* You&#039;ll be prompted to enter your wifi SSID and wifi password. &#039;&#039;&#039;Note: Your device can only use a 2.4GHz network&#039;&#039;&#039;: it is not compatible with 5GHz WiFi.&lt;br /&gt;
* The badge will restart using the credentials you&#039;ve provided and it will shut down its wifi access point. &lt;br /&gt;
   [[File:configurewifi-4.png|300px]]&lt;br /&gt;
* Your phone/computer will go back to using its usual wifi network and badge is now online!&lt;br /&gt;
&lt;br /&gt;
Note: If you are using an Android device to link the badge to your WiFi, it will pop up a dialog to say you are switching to a network that doesn&#039;t have Internet access and ask if you want to switch back. Select &amp;quot;Keep&amp;quot; to stay on the badge&#039;s temporary access point.&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - commandline with mpfshell ===&lt;br /&gt;
&lt;br /&gt;
If the above guide to setting up via the wifi AP (access point) doesn&#039;t work, you can put a configuration file onto the badge. You&#039;ll need a Python environment to do so, which you&#039;ll need anyway if you plan on writing your own badge software applications.&lt;br /&gt;
&lt;br /&gt;
* Start by getting [[Swagbadge2021_UpdatingSoftware|a copy of the aiko firmware, and installing mpfshell]]&lt;br /&gt;
* &#039;&#039;Note: Your device can only talk to a 2.4GHz network: it is not compatible with 5GHz.&#039;&#039;&lt;br /&gt;
* Edit aiko_engine_mp/configuration/net.py and insert the details of your SSID and password.&lt;br /&gt;
* use mpfshell: &amp;lt;code&amp;gt;mpfshell -o COM3&amp;lt;/code&amp;gt; (substitute the com port/tty of your badge)&lt;br /&gt;
* &amp;lt;code&amp;gt;put configuration/net.py configuration/net.py&amp;lt;/code&amp;gt;&lt;br /&gt;
* fire up repl to view the console log &lt;br /&gt;
* You can now restart your device&lt;br /&gt;
* On bootup it should now talk to your network and you can see it on the console log.&lt;br /&gt;
&lt;br /&gt;
Your badge will display its connection status on the screens.&lt;br /&gt;
&lt;br /&gt;
= Running pre-installed applications =&lt;br /&gt;
&lt;br /&gt;
== Aiko&#039;s minimal Swagbadge application ==&lt;br /&gt;
At the moment the badge by default a basic &amp;quot;Swagbadge&amp;quot; application within the Aiko framework. This application&lt;br /&gt;
* has a thread to keep wifi running, &lt;br /&gt;
* has a thread to stay connected to (our Australian, private) mqtt server&lt;br /&gt;
* has a thread to display a rotating header across the two oleds.&lt;br /&gt;
&lt;br /&gt;
You can now talk to your badge [[Swagbadge2021_MQTT|using MQTT messages]].&lt;br /&gt;
&lt;br /&gt;
== Running other applications ==&lt;br /&gt;
At the moment, &amp;quot;swagbadge&amp;quot; is the only application that&#039;s for use with the badge. &lt;br /&gt;
&lt;br /&gt;
There are [https://github.com/geekscape/aiko_engine_mp/tree/master/applications other applications] in the repo which are for other places the Aiko framework has been used.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve written an application of your own and want to run that by default on badge startup, &lt;br /&gt;
# edit your local copy of configuration/main.py and change the value of the &amp;quot;application&amp;quot; to point to your new application.&lt;br /&gt;
# using mpfshell, &#039;put&#039; configuration/main.py and applications/your_application.py onto the badge&lt;br /&gt;
# Restart the badge&lt;br /&gt;
&lt;br /&gt;
== Running example code ==&lt;br /&gt;
There is [https://github.com/geekscape/aiko_engine_mp/tree/master/examples example code] which has a number of examples in it, including a snake game and a demo of how to use various badge functions.&lt;br /&gt;
&lt;br /&gt;
# From your commandline on your computer, use mpfshell to put whatever example code you want onto the badge.&lt;br /&gt;
# To run example code, you can use the &amp;quot;emergency stop&amp;quot; function to halt any other applications and put you in the repl.&lt;br /&gt;
## Touch both of the bottom spots on the sliders&lt;br /&gt;
## Reboot the badge&lt;br /&gt;
# Now at the repl prompt, type (replace the name of the module as appropriate for the code you want to run): &lt;br /&gt;
&lt;br /&gt;
Use examples.game_snake as example:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
from examples.game_snake import run&lt;br /&gt;
run()&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ctrl-c to halt operation and return to the repl prompt.&lt;br /&gt;
&lt;br /&gt;
= Hardware pinout =&lt;br /&gt;
&lt;br /&gt;
You can get the schematic and pin mapping on this page: https://github.com/CCHS-Melbourne/Swag-Badge/blob/master/swag-badge-schematic.pdf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- GPIO0 : left breakout pin4&lt;br /&gt;
- GPIO2 : left breakout pin3&lt;br /&gt;
&lt;br /&gt;
- GPIO4 : SCL (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO5 : SDA (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO12/15: slider #1&lt;br /&gt;
- GPIO13: left breakout pin3&lt;br /&gt;
- GPIO14/27: slider #2&lt;br /&gt;
- GPIO16: left switch  (under screen #1)&lt;br /&gt;
- GPIO17: right switch (under screen #2)&lt;br /&gt;
&lt;br /&gt;
- GPIO18: SAO3 pin3 + LB pin7&lt;br /&gt;
- GPIO23: SAO3 pin4&lt;br /&gt;
&lt;br /&gt;
- GPIO19: SAO1 pin4&lt;br /&gt;
- GPIO22: SAO1 pin3 (also onboard blue LED in the back)&lt;br /&gt;
&lt;br /&gt;
- GPIO21: unused but not wired on this chip&lt;br /&gt;
&lt;br /&gt;
- GPIO25: SAO4 pin4 + RB pin6&lt;br /&gt;
- GPIO26: SAO4 pin3 + RB pin7&lt;br /&gt;
&lt;br /&gt;
- GPIO27: free (pin available on the chip, not routed anywhere)&lt;br /&gt;
&lt;br /&gt;
- GPIO32: SAO2 pin3 + RB pin4 (touch pin, can be used with SAO tux foot or nose touchpad) &lt;br /&gt;
- GPIO33: SAO2 pin4 + RB pin5 (touch pin, can be used with SAO tux foot or nose touchpad)&lt;br /&gt;
&lt;br /&gt;
- GPIO34: right breakout pin2 (input only)&lt;br /&gt;
- GPIO35: right breakout pin3 (input only)&lt;br /&gt;
&lt;br /&gt;
- GPIO36: unused but not wired on this chip (input only)&lt;br /&gt;
- GPIO39: unused but not wired on this chip (input only)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Hardware SPI for a device like SSD1331 ==&lt;br /&gt;
ESP32 has 2 DMA capable hardware SPI busses usable by the user: SPI2/HSPI and SPI3/VSPI (see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/spi_master.html and https://github.com/espressif/arduino-esp32/blob/master/libraries/SPI/examples/SPI_Multiple_Buses/SPI_Multiple_Buses.ino for how to use them at the same time ). The important note in the espressif doc is that if you do not use the dedicated default HWSPI pins, they get routed through a hardware MUX and your maximum SPI speed is lowered from 80Mhz to 40Mhz.&lt;br /&gt;
&lt;br /&gt;
If you would like to connect an SPI device like an SSD1331 96x64 color TFT, here are default hardware pin numbers, and &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  SD1331 Pin	        ESP32	ESP32&lt;br /&gt;
1 GND                   VSPI    HSPI &lt;br /&gt;
2 VCC&lt;br /&gt;
3 SCL/SCK/CLK/D0	18	14   &lt;br /&gt;
4 SDA/SDI/MOSI/D1	23	13   &lt;br /&gt;
---- 2 pins above and MISO are HWSPI, pins below are anything&lt;br /&gt;
---- RST is not part of SPI, it&#039;s an out of band signal to reset a TFT&lt;br /&gt;
---- This could be wired to the ESP32 EN(reset) pin&lt;br /&gt;
5 RES/RST		26	26   &lt;br /&gt;
---- Data/Command pin is not part of SPI but used to tell the TFT if incoming SPI&lt;br /&gt;
---- data is actually a command, or pixel data.&lt;br /&gt;
6 DC/A0/RS (data)	25	25   &lt;br /&gt;
---- Cable select chooses which SPI device we&#039;re talking to, if there is only&lt;br /&gt;
---- one, it can be tied to ground. Any pin is fine&lt;br /&gt;
7 CS/SS =&amp;gt; GND	        27	15   &lt;br /&gt;
&lt;br /&gt;
---- MISO is not used to talk to TFTs, and is a hardware pin, but unused here&lt;br /&gt;
  MISO		        19	12    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
pins 12/13/14 are already used by the badge, but 18/19/23 are usable (SAO3 and SAO1), and since MISO is unused, you could also assign it to GPIO21 which isn&#039;t wired at all on the lolin lite chip.&lt;br /&gt;
&lt;br /&gt;
= Extensions: Adding a SAO =&lt;br /&gt;
* provided by others&lt;br /&gt;
* build your own (linky here to our docs)&lt;br /&gt;
&lt;br /&gt;
= Extensions: Writing your own applications =&lt;br /&gt;
&lt;br /&gt;
Between when we ship the board and when it arrives, there might be some changes to the software framework (Aiko). Here&#039;s how to update it. Or perhaps you&#039;re interested in writing your own applications? &lt;br /&gt;
&lt;br /&gt;
* [[Swagbadge2021_UpdatingSoftware|Updating the Software]]&lt;br /&gt;
* [[Swagbadge2021_SoftwareDev|Writing your own badge programs]]&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1324</id>
		<title>Swagbadge2021 GettingStarted</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1324"/>
		<updated>2021-01-23T20:28:58Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Hardware pinout */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Getting started with the Swagbadge =&lt;br /&gt;
&lt;br /&gt;
== Support ==&lt;br /&gt;
* The [https://spectrum.chat/lca2021-swagbadge Swag Badge Spectrum chat] is a place where the badge team hangs out, ready to answer your questions.&lt;br /&gt;
&lt;br /&gt;
== My package arrived in the mail, first steps. ==&lt;br /&gt;
* Your package should contain your badge, and some other goodies! &lt;br /&gt;
** [[File:swagbadgepackage.jpg|400px|alt=Image showing the contents of the swagbag package]]&lt;br /&gt;
** Badge&lt;br /&gt;
** SAO headers (x 4)&lt;br /&gt;
** SAO proto boards (x 2)&lt;br /&gt;
** SAO tux board&lt;br /&gt;
** Lanyard&lt;br /&gt;
** Stickers&lt;br /&gt;
** Instructions&lt;br /&gt;
* Take off the protective cases to reveal the screens.&lt;br /&gt;
* Powering it up&lt;br /&gt;
** Insert a micro USB cable into the badge and connect the other end to a USB port on your computer or USB power source.&lt;br /&gt;
** A green light should glow on the rear of the board, and a title appear across the two screens.&lt;br /&gt;
* Turning it on and off again&lt;br /&gt;
** Plugging/unplugging it is fine. Usually the badge isn&#039;t running anything intensely enough that just unpowering it would cause a problem.&lt;br /&gt;
* On bootup, you should see:&lt;br /&gt;
** The OLED screens will display &amp;quot;Aiko&amp;quot; and a version number as a title&lt;br /&gt;
** It will also display something else to tell you to set up your wifi.&lt;br /&gt;
&lt;br /&gt;
== Getting it on your network ==&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - wireless ===&lt;br /&gt;
&lt;br /&gt;
The first time you boot your badge, it won&#039;t know how to talk to your wifi network, so it creates its own temporary wifi network for you to connect to, so you can configure it.&lt;br /&gt;
&lt;br /&gt;
* Start your badge by plugging it in.&lt;br /&gt;
* The screens on your badge will say &amp;lt;code&amp;gt;Configure WiFi:&amp;lt;/code&amp;gt; &lt;br /&gt;
   [[File:configurewifi-1.png|300px]]&lt;br /&gt;
* Use your phone (or computer) to change wifi networks to use the badge. The badge wifi name starts with &amp;lt;code&amp;gt;aiko&amp;lt;/code&amp;gt; followed by some numbers/letters. &lt;br /&gt;
   [[File:configurewifi-2.png|200px]] -&amp;gt; [[File:configurewifi-3.png|200px]]&lt;br /&gt;
* Once you&#039;re connected to the badge wifi, open a web browser on that device to the IP address shown on the screens. Something like &amp;lt;code&amp;gt;http://192.168.4.1&amp;lt;/code&amp;gt; &lt;br /&gt;
   [[File:configurewifi-5.png|300px]]&lt;br /&gt;
* You&#039;ll be prompted to enter your wifi SSID and wifi password. &#039;&#039;&#039;Note: Your device can only use a 2.4GHz network&#039;&#039;&#039;: it is not compatible with 5GHz WiFi.&lt;br /&gt;
* The badge will restart using the credentials you&#039;ve provided and it will shut down its wifi access point. &lt;br /&gt;
   [[File:configurewifi-4.png|300px]]&lt;br /&gt;
* Your phone/computer will go back to using its usual wifi network and badge is now online!&lt;br /&gt;
&lt;br /&gt;
Note: If you are using an Android device to link the badge to your WiFi, it will pop up a dialog to say you are switching to a network that doesn&#039;t have Internet access and ask if you want to switch back. Select &amp;quot;Keep&amp;quot; to stay on the badge&#039;s temporary access point.&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - commandline with mpfshell ===&lt;br /&gt;
&lt;br /&gt;
If the above guide to setting up via the wifi AP (access point) doesn&#039;t work, you can put a configuration file onto the badge. You&#039;ll need a Python environment to do so, which you&#039;ll need anyway if you plan on writing your own badge software applications.&lt;br /&gt;
&lt;br /&gt;
* Start by getting [[Swagbadge2021_UpdatingSoftware|a copy of the aiko firmware, and installing mpfshell]]&lt;br /&gt;
* &#039;&#039;Note: Your device can only talk to a 2.4GHz network: it is not compatible with 5GHz.&#039;&#039;&lt;br /&gt;
* Edit aiko_engine_mp/configuration/net.py and insert the details of your SSID and password.&lt;br /&gt;
* use mpfshell: &amp;lt;code&amp;gt;mpfshell -o COM3&amp;lt;/code&amp;gt; (substitute the com port/tty of your badge)&lt;br /&gt;
* &amp;lt;code&amp;gt;put configuration/net.py configuration/net.py&amp;lt;/code&amp;gt;&lt;br /&gt;
* fire up repl to view the console log &lt;br /&gt;
* You can now restart your device&lt;br /&gt;
* On bootup it should now talk to your network and you can see it on the console log.&lt;br /&gt;
&lt;br /&gt;
Your badge will display its connection status on the screens.&lt;br /&gt;
&lt;br /&gt;
= Running pre-installed applications =&lt;br /&gt;
&lt;br /&gt;
== Aiko&#039;s minimal Swagbadge application ==&lt;br /&gt;
At the moment the badge by default a basic &amp;quot;Swagbadge&amp;quot; application within the Aiko framework. This application&lt;br /&gt;
* has a thread to keep wifi running, &lt;br /&gt;
* has a thread to stay connected to (our Australian, private) mqtt server&lt;br /&gt;
* has a thread to display a rotating header across the two oleds.&lt;br /&gt;
&lt;br /&gt;
You can now talk to your badge [[Swagbadge2021_MQTT|using MQTT messages]].&lt;br /&gt;
&lt;br /&gt;
== Running other applications ==&lt;br /&gt;
At the moment, &amp;quot;swagbadge&amp;quot; is the only application that&#039;s for use with the badge. &lt;br /&gt;
&lt;br /&gt;
There are [https://github.com/geekscape/aiko_engine_mp/tree/master/applications other applications] in the repo which are for other places the Aiko framework has been used.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve written an application of your own and want to run that by default on badge startup, &lt;br /&gt;
# edit your local copy of configuration/main.py and change the value of the &amp;quot;application&amp;quot; to point to your new application.&lt;br /&gt;
# using mpfshell, &#039;put&#039; configuration/main.py and applications/your_application.py onto the badge&lt;br /&gt;
# Restart the badge&lt;br /&gt;
&lt;br /&gt;
== Running example code ==&lt;br /&gt;
There is [https://github.com/geekscape/aiko_engine_mp/tree/master/examples example code] which has a number of examples in it, including a snake game and a demo of how to use various badge functions.&lt;br /&gt;
&lt;br /&gt;
# From your commandline on your computer, use mpfshell to put whatever example code you want onto the badge.&lt;br /&gt;
# To run example code, you can use the &amp;quot;emergency stop&amp;quot; function to halt any other applications and put you in the repl.&lt;br /&gt;
## Touch both of the bottom spots on the sliders&lt;br /&gt;
## Reboot the badge&lt;br /&gt;
# Now at the repl prompt, type (replace the name of the module as appropriate for the code you want to run): &lt;br /&gt;
&lt;br /&gt;
Use examples.game_snake as example:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
from examples.game_snake import run&lt;br /&gt;
run()&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ctrl-c to halt operation and return to the repl prompt.&lt;br /&gt;
&lt;br /&gt;
= Hardware pinout =&lt;br /&gt;
&lt;br /&gt;
You can get the schematic and pin mapping on this page: https://github.com/CCHS-Melbourne/Swag-Badge/blob/master/swag-badge-schematic.pdf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- GPIO0 : left breakout pin4&lt;br /&gt;
- GPIO2 : left breakout pin3&lt;br /&gt;
&lt;br /&gt;
- GPIO4 : SCL (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO5 : SDA (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO12/15: slider #1&lt;br /&gt;
- GPIO13: left breakout pin3&lt;br /&gt;
- GPIO14/27: slider #2&lt;br /&gt;
- GPIO16: left switch  (under screen #1)&lt;br /&gt;
- GPIO17: right switch (under screen #2)&lt;br /&gt;
&lt;br /&gt;
- GPIO18: SAO3 pin3 + LB pin7&lt;br /&gt;
- GPIO23: SAO3 pin4&lt;br /&gt;
&lt;br /&gt;
- GPIO19: SAO1 pin4&lt;br /&gt;
- GPIO22: SAO1 pin3 (also onboard blue LED in the back)&lt;br /&gt;
&lt;br /&gt;
- GPIO21: unused but not wired on this chip&lt;br /&gt;
&lt;br /&gt;
- GPIO25: SAO4 pin4 + RB pin6&lt;br /&gt;
- GPIO26: SAO4 pin3 + RB pin7&lt;br /&gt;
&lt;br /&gt;
- GPIO27: free (pin available on the chip, not routed anywhere)&lt;br /&gt;
&lt;br /&gt;
- GPIO32: SAO2 pin3 + RB pin4 (touch pin, can be used with SAO tux foot or nose touchpad) &lt;br /&gt;
- GPIO33: SAO2 pin4 + RB pin5 (touch pin, can be used with SAO tux foot or nose touchpad)&lt;br /&gt;
&lt;br /&gt;
- GPIO34: right breakout pin2 (input only)&lt;br /&gt;
- GPIO35: right breakout pin3 (input only)&lt;br /&gt;
&lt;br /&gt;
- GPIO36: unused but not wired on this chip (input only)&lt;br /&gt;
- GPIO39: unused but not wired on this chip (input only)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Hardware SPI for a device like SSD1331 ==&lt;br /&gt;
ESP32 has 2 DMA capable hardware SPI busses usable by the user: SPI2/HSPI and SPI3/VSPI (see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/spi_master.html and https://github.com/espressif/arduino-esp32/blob/master/libraries/SPI/examples/SPI_Multiple_Buses/SPI_Multiple_Buses.ino for how to use them at the same time ).  If you would like to connect an SPI device like an SSD1331 96x64 color TFT, here are default hardware pin numbers, and &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  SD1331 Pin	        ESP32	ESP32&lt;br /&gt;
1 GND                   VSPI    HSPI &lt;br /&gt;
2 VCC&lt;br /&gt;
3 SCL/SCK/CLK/D0	18	14   &lt;br /&gt;
4 SDA/SDI/MOSI/D1	23	13   &lt;br /&gt;
---- 2 pins above and MISO are HWSPI, pins below are anything&lt;br /&gt;
---- RST is not part of SPI, it&#039;s an out of band signal to reset a TFT&lt;br /&gt;
---- This could be wired to the ESP32 EN(reset) pin&lt;br /&gt;
5 RES/RST		26	26   &lt;br /&gt;
---- Data/Command pin is not part of SPI but used to tell the TFT if incoming SPI&lt;br /&gt;
---- data is actually a command, or pixel data.&lt;br /&gt;
6 DC/A0/RS (data)	25	25   &lt;br /&gt;
---- Cable select chooses which SPI device we&#039;re talking to, if there is only&lt;br /&gt;
---- one, it can be tied to ground. Any pin is fine&lt;br /&gt;
7 CS/SS =&amp;gt; GND	        27	15   &lt;br /&gt;
&lt;br /&gt;
---- MISO is not used to talk to TFTs, and is a hardware pin, but unused here&lt;br /&gt;
  MISO		        19	12    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
pins 12/13/14 are already used by the badge, but 18/19/23 are usable (SAO3 and SAO1), and since MISO is unused, you could also assign it to GPIO21 which isn&#039;t wired at all on the lolin lite chip.&lt;br /&gt;
&lt;br /&gt;
= Extensions: Adding a SAO =&lt;br /&gt;
* provided by others&lt;br /&gt;
* build your own (linky here to our docs)&lt;br /&gt;
&lt;br /&gt;
= Extensions: Writing your own applications =&lt;br /&gt;
&lt;br /&gt;
Between when we ship the board and when it arrives, there might be some changes to the software framework (Aiko). Here&#039;s how to update it. Or perhaps you&#039;re interested in writing your own applications? &lt;br /&gt;
&lt;br /&gt;
* [[Swagbadge2021_UpdatingSoftware|Updating the Software]]&lt;br /&gt;
* [[Swagbadge2021_SoftwareDev|Writing your own badge programs]]&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_UpdatingSoftware&amp;diff=1320</id>
		<title>Swagbadge2021 UpdatingSoftware</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_UpdatingSoftware&amp;diff=1320"/>
		<updated>2021-01-20T06:47:26Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Download #swagbadge (Aiko Engine) firmware */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Updating the software framework =&lt;br /&gt;
&lt;br /&gt;
Swagbadge owners might want to update the software framework (Aiko). Dagbadge owners will need to put the framework onto their badge before they can use it.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s how to do that!&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
* #swagbadge or #dagbadge or any ESP32 with an OLED screen&lt;br /&gt;
* Micro-USB cable&lt;br /&gt;
* Linux, Mac OS or Linux system running Python 3&lt;br /&gt;
* Command line tools: git&lt;br /&gt;
&lt;br /&gt;
== Setting up your Windows 10 system for connecting to badge hardware ==&lt;br /&gt;
&lt;br /&gt;
How to find your serial COM port on Windows: &lt;br /&gt;
* Use the Device Manager. &lt;br /&gt;
* Under the &amp;quot;Ports&amp;quot; category, you&#039;ll see one or more entries. Hopefully one of which is your badge! It will tell you what Port it is on. &lt;br /&gt;
* If you can&#039;t see your badge, you might need to go up to the View menu and use &amp;quot;Show hidden devices&amp;quot; and see if that helps.&lt;br /&gt;
&lt;br /&gt;
Windows 10 may automatically discover your #swagbadge USB hardware and automatically install the correct USB serial hardware driver, or if nothing still shows up, you might need to update your USB drivers for supporting the USB hardware CP210x on your #swagbadge, please follow these instructions:&lt;br /&gt;
* Download the CP210x drivers from [https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers Silicon Labs Windows Universal Driver]&lt;br /&gt;
* Unpack the zip file&lt;br /&gt;
* Follow the Silicon Labs instructions for [https://www.silabs.com/documents/public/application-notes/AN335.pdf INF only install] (Section 5 on page 9)&lt;br /&gt;
&lt;br /&gt;
By this point, you have know the serial COM port that your #swagbadge is connected to, e.g COM4&lt;br /&gt;
&lt;br /&gt;
== Setting up your Mac OS system for connecting to #swagbadge hardware ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How to find your serial COM port on OS X: &lt;br /&gt;
&lt;br /&gt;
    $ ls /dev/tty.usb*&lt;br /&gt;
&lt;br /&gt;
Unless you have lot of dev boards (or maybe a phone) plugged in you should just see a single filename there.&lt;br /&gt;
Use this (without the `/dev/` prefix) when using the `open` command in `mpfshell`&lt;br /&gt;
&lt;br /&gt;
To get a working `mpfshell` install a recent version of Python (Python3.8 is known to work) using a installed DMG.&lt;br /&gt;
Then create a *venv* and install the necessary tools using pip.&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
    $ mkdir swag&lt;br /&gt;
    $ cd swag&lt;br /&gt;
    $ python3.8 -m venv env&lt;br /&gt;
    $ ./env/bin/pip install esptool mpfshell&lt;br /&gt;
&lt;br /&gt;
You can then run `mpfshell` to connect:&lt;br /&gt;
&lt;br /&gt;
    $ ./env/bin/mpfshell&lt;br /&gt;
    mpfs [/]&amp;gt; open &amp;lt;your device node as found previously&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setting up your Linux system for connecting to #swagbadge hardware ==&lt;br /&gt;
[Link other instructions here]&lt;br /&gt;
&lt;br /&gt;
== Setting up your Windows 10 system for installing #swagbadge firmware == &lt;br /&gt;
&lt;br /&gt;
* Install [https://docs.conda.io/en/latest/miniconda.html Miniconda3] to create a specific Python development environment. (Note we are using Python3 not Python2)&lt;br /&gt;
* Create specific Python 3 environment for playing around with your #swagbadge&lt;br /&gt;
** Start an Anaconda Powershell Prompt (aka Windows Terminal)&lt;br /&gt;
** &amp;lt;code&amp;gt;conda create --yes -n swagbadge python=3&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;conda activate swagbadge&amp;lt;/code&amp;gt;&lt;br /&gt;
* Your command prompt should now look like: &amp;lt;code&amp;gt;(swagbadge) C:\Users\[Username]&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Install some python tools to let us prepare and communicate with the badge&lt;br /&gt;
** &amp;lt;code&amp;gt;pip install esptool mpfshell&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To test that the required tools are installed, trying running the following commands&lt;br /&gt;
** &amp;lt;code&amp;gt;esptool&amp;lt;/code&amp;gt;  # Should show you help on running the esptool&lt;br /&gt;
** &amp;lt;code&amp;gt;mpfshell&amp;lt;/code&amp;gt;  # Should show three lines of output&lt;br /&gt;
*** &amp;lt;code&amp;gt;exit&amp;lt;/code&amp;gt;  #  To exit mpfshell&lt;br /&gt;
&lt;br /&gt;
== Download #swagbadge (Aiko Engine) firmware ==&lt;br /&gt;
&lt;br /&gt;
Within your Anaconda Prompt session, change directory to where you’d like the #swagbadge software to be downloaded, for example:&lt;br /&gt;
* &amp;lt;code&amp;gt;cd $HOME/software&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Download #swagbadge firmware:&lt;br /&gt;
* &amp;lt;code&amp;gt;git clone https://github.com/geekscape/aiko_engine_mp.git&amp;lt;/code&amp;gt; # NOTE: this URL will change once we&#039;re live&lt;br /&gt;
* &amp;lt;code&amp;gt;cd aiko_engine_mp&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Install MicroPython&lt;br /&gt;
* Create a directory to hold the MicroPython firmware, such as aiko_engine_mp/firmware/&lt;br /&gt;
* &amp;lt;code&amp;gt;mkdir firmware&amp;lt;/code&amp;gt;&lt;br /&gt;
* Using your web browser, download: [http://micropython.org/resources/firmware/esp32-idf4-20200902-v1.13.bin esp32-idf4-20200902-v1.13.bin] (mouse right button click → [Save As …]  saving the MicroPython firmware in the firmware directory you just made.&lt;br /&gt;
** The [http://micropython.org/download/ MicroPython download list] has a link to a bunch of firmware drivers, we are using the one for the esp32 device, with the latest 1.4 generic&lt;br /&gt;
&lt;br /&gt;
Erase #swagbadge LoLin-Lite ESP32 flash memory&lt;br /&gt;
* &amp;lt;code&amp;gt;esptool --chip esp32 --port COM3 erase_flash&amp;lt;/code&amp;gt; # adjust the port to suit.&lt;br /&gt;
* You’ll know it’s worked, if the output finishes with “Hard resetting via RTS pin…”&lt;br /&gt;
&lt;br /&gt;
You may get this error, if so, try esptool.py instead:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sauron [mc]$ esptool --chip esp32 --port /dev/ttyUSB0 erase_flash&lt;br /&gt;
esptool.py v2.8&lt;br /&gt;
Serial port /dev/ttyUSB0&lt;br /&gt;
Connecting....&lt;br /&gt;
Chip is ESP32D0WDQ6 (revision 1)&lt;br /&gt;
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None&lt;br /&gt;
Crystal is 40MHz&lt;br /&gt;
MAC: 7c:9e:bd:ed:79:24&lt;br /&gt;
Enabling default SPI flash mode...&lt;br /&gt;
Erasing flash (this may take a while)...&lt;br /&gt;
&lt;br /&gt;
A fatal error occurred: ESP32 ROM does not support function erase_flash.&lt;br /&gt;
sauron [mc]$ esptool.py --chip esp32 --port /dev/ttyUSB0 erase_flash&lt;br /&gt;
esptool.py v2.6&lt;br /&gt;
Serial port /dev/ttyUSB0&lt;br /&gt;
Connecting....&lt;br /&gt;
Chip is ESP32D0WDQ6 (revision 1)&lt;br /&gt;
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None&lt;br /&gt;
MAC: 7c:9e:bd:ed:79:24&lt;br /&gt;
Uploading stub...&lt;br /&gt;
Running stub...&lt;br /&gt;
Stub running...&lt;br /&gt;
Erasing flash (this may take a while)...&lt;br /&gt;
Chip erase completed successfully in 11.8s&lt;br /&gt;
Hard resetting via RTS pin...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Install microPython on the badge&lt;br /&gt;
* &amp;lt;code&amp;gt;esptool --chip esp32 --port COM3 --baud 460800 write_flash -z 0x1000 firmware\esp32-idf4-20200902-v1.13.bin&amp;lt;/code&amp;gt; #adjust port and firmware location if necessary&lt;br /&gt;
* You’ll know it’s worked, if the output finishes with “Hard resetting via RTS pin…”&lt;br /&gt;
&lt;br /&gt;
Test that the software is installed correctly by using mpfshell&lt;br /&gt;
* &amp;lt;code&amp;gt;mpfshell -o COM3&amp;lt;/code&amp;gt; # Adjust port to suit&lt;br /&gt;
* If it has made a connection to your badge, you will see it say&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;Connected to esp32&lt;br /&gt;
** Micropython File Shell v0.9.1, sw@kaltpost.de **&lt;br /&gt;
-- Running on Python 3.8 using PySerial 3.4 --&lt;br /&gt;
mpfs [/]&amp;gt; &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using mpfshell ==&lt;br /&gt;
&lt;br /&gt;
mpfshell has two functions: it lets you put files on/off the device, and it can give you a python shell to execute code on the device.&lt;br /&gt;
* Getting files on/off the device is a bit like commandline ftp&lt;br /&gt;
** ls - looks at the files on your micropython device&lt;br /&gt;
** lls - looks at the files on your local computer in the current directory&lt;br /&gt;
** put - puts a file to the device&lt;br /&gt;
** cat - shows you the contents of the file&lt;br /&gt;
** help() - gives you more information on the commands&lt;br /&gt;
** repl - opens up the python shell on the badge&lt;br /&gt;
&lt;br /&gt;
Note: To get out of repl, use Ctrl-Q (on Windows) which drops you back into mpfshell&lt;br /&gt;
&lt;br /&gt;
A little program to say hello world!&lt;br /&gt;
* &amp;lt;code&amp;gt; &amp;gt;&amp;gt;&amp;gt; print(&amp;quot;hello world&amp;quot;)&amp;lt;/code&amp;gt;&lt;br /&gt;
* Output: &amp;lt;code&amp;gt;hello world&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A little program to turn the blue light on the board on and off (this is on the underside of the Swagbadge, visible through a circular cutout)&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&amp;gt;&amp;gt;&amp;gt; import machine&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; pin22=machine.Pin(22, machine.Pin.OUT, machine.Pin.PULL_UP)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; pin22.value(0) &lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; pin22.value(1)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Alternatives to mpfshell: rshell and pyboard.py ==&lt;br /&gt;
&lt;br /&gt;
rshell is an option, but it may not be reliable in all cases. However &#039;pip install rshell&#039; also installs pyboard.&lt;br /&gt;
&lt;br /&gt;
pyboard.py is the official tool that ships with micropython and is more flexible and reliable: http://docs.micropython.org/en/latest/reference/pyboard.py.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sauron [mc]$ pyboard.py --device /dev/ttyUSB0 -c &#039;import os; print(os.statvfs(&amp;quot;/&amp;quot;)[0]*os.statvfs(&amp;quot;/&amp;quot;)[3], &amp;quot;bytes free out of&amp;quot;,os.statvfs(&amp;quot;/&amp;quot;)[1]*os.statvfs(&amp;quot;/&amp;quot;)[2])&#039;&lt;br /&gt;
1699840 bytes free out of 2097152&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Saving your private key ==&lt;br /&gt;
&lt;br /&gt;
Use mpfshell to get the file: `configuration/keys.db`.&lt;br /&gt;
&lt;br /&gt;
== Putting the Aiko framework onto the device, using mpfshell == &lt;br /&gt;
* &amp;lt;code&amp;gt;mpfshell COM5 -s scripts\aiko.mpf&amp;lt;/code&amp;gt; #run from within the aiko_framework_mp directory&lt;br /&gt;
&lt;br /&gt;
=== Windows only: Patch mpfshell ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note!&#039;&#039; mpfshell needs a patch applied to let it run a script under Windows. (the patch is included upstream, it&#039;s just not in a released distribution yet)&lt;br /&gt;
&lt;br /&gt;
* Inside &amp;lt;code&amp;gt;C:/users/USERNAME/Miniconda2/envs/swagbadge/Lib/site-packages/mp&amp;lt;/code&amp;gt;&lt;br /&gt;
* edit &amp;lt;code&amp;gt;mpfshell.py&amp;lt;/code&amp;gt;&lt;br /&gt;
* Search for &amp;lt;code&amp;gt;elif args.script is not None:&amp;lt;/code&amp;gt;, around line 796&lt;br /&gt;
* between that line and the next, insert two lines. It should look like:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
    elif args.script is not None:&lt;br /&gt;
&lt;br /&gt;
        if platform.system() == &amp;quot;Windows&amp;quot;:  #INSERT THIS LINE&lt;br /&gt;
            mpfs.use_rawinput = True        #INSERT THIS LINE&lt;br /&gt;
&lt;br /&gt;
        f = open(args.script, &amp;quot;r&amp;quot;)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* Python is very particular about spacing. The rest of the code uses 4 spaces for indents so follow suit.&lt;br /&gt;
&lt;br /&gt;
= Software development =&lt;br /&gt;
&lt;br /&gt;
See [[Swagbadge2021_SoftwareDev]]&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1305</id>
		<title>Swagbadge2021 GettingStarted</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1305"/>
		<updated>2021-01-19T23:16:16Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Hardware pinout */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Getting started with the Swagbadge =&lt;br /&gt;
&lt;br /&gt;
== Support ==&lt;br /&gt;
* The [https://spectrum.chat/lca2021-swagbadge Swag Badge Spectrum chat] is a place where the badge team hangs out, ready to answer your questions.&lt;br /&gt;
&lt;br /&gt;
== My package arrived in the mail, first steps. ==&lt;br /&gt;
* Your package should contain your badge, and some other goodies! &lt;br /&gt;
** [[File:swagbadgepackage.jpg|400px|alt=Image showing the contents of the swagbag package]]&lt;br /&gt;
** Badge&lt;br /&gt;
** SAO headers (x 4)&lt;br /&gt;
** SAO proto boards (x 2)&lt;br /&gt;
** SAO tux board&lt;br /&gt;
** Lanyard&lt;br /&gt;
** Stickers&lt;br /&gt;
** Instructions&lt;br /&gt;
* Take off the protective cases to reveal the screens.&lt;br /&gt;
* Powering it up&lt;br /&gt;
** Insert a micro USB cable into the badge and connect the other end to a USB port on your computer or USB power source.&lt;br /&gt;
** A green light should glow on the rear of the board, and a title appear across the two screens.&lt;br /&gt;
* Turning it on and off again&lt;br /&gt;
** Plugging/unplugging it is fine. Usually the badge isn&#039;t running anything intensely enough that just unpowering it would cause a problem.&lt;br /&gt;
* On bootup, you should see:&lt;br /&gt;
** The OLED screens will display &amp;quot;Aiko&amp;quot; and a version number as a title&lt;br /&gt;
** It will also display something else to tell you to set up your wifi.&lt;br /&gt;
&lt;br /&gt;
== Getting it on your network ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Safety precautions we have provided&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* When using any hardware ordered off the internet, you can&#039;t be quite certain what software might be present on it. Before shipping these badges to you, we reflashed a fresh copy of MicroPython onto the Lolin32.&lt;br /&gt;
* The framework running on the badge is Aiko, which is open source.&lt;br /&gt;
* The software on the badge is available on the CCHS repository, also all open source.&lt;br /&gt;
* The badges are designed to communicate over MQTT - a lightweight standard for messaging on IoT devices, but we are aware of privacy considerations: you don&#039;t want anybody able to control your badge from afar. The swagbadge protocol provides support for encrypted messages.&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - wireless ===&lt;br /&gt;
&lt;br /&gt;
* The first time you boot your device, it won&#039;t know how to talk to your network. If it can&#039;t detect a pre-existing set of network credentials, or connect to anything it knows about, it will establish a temporary access point and prompt you to navigate to it to enter your wifi details.&lt;br /&gt;
* &#039;&#039;Note: Your device can only talk to a 2.4GHz network: it is not compatible with 5GHz WiFi.&#039;&#039;&lt;br /&gt;
* The screens on your badge will say: &amp;lt;code&amp;gt;Configure WiFi: aiko1234a12341234. Try http://192.168.4.1&amp;lt;/code&amp;gt;&lt;br /&gt;
* Use your phone or computer to connect to the wifi network on the badge. Its name starts with &amp;lt;code&amp;gt;aiko&amp;lt;/code&amp;gt; followed by some numbers/letters.&lt;br /&gt;
* Once you&#039;re connected to the badge, open a web browser to the IP address on the screens. Something like &amp;lt;code&amp;gt;http://192.168.4.1&amp;lt;/code&amp;gt;&lt;br /&gt;
* You&#039;ll be prompted to enter your wifi SSID and wifi password.&lt;br /&gt;
* Once you&#039;ve saved that, the badge will restart using the credentials you&#039;ve provided and it will shut down its wifi access point.&lt;br /&gt;
&lt;br /&gt;
Note: If you are using an Android device to link the badge to your WiFi, it will pop up a dialog to say you are switching to a network that doesn&#039;t have Internet access and ask if you want to switch back. Select &amp;quot;Keep&amp;quot; to stay on the badge&#039;s temporary access point.&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - commandline with mpfshell ===&lt;br /&gt;
&lt;br /&gt;
* If setting up via the wifi AP (access point) doesn&#039;t work, you can put a configuration file onto the badge.&lt;br /&gt;
* You&#039;ll need to start by getting [[Swagbadge2021_UpdatingSoftware|a copy of the aiko firmware, and installing mpfshell]]&lt;br /&gt;
* &#039;&#039;Note: Your device can only talk to a 2.4GHz network: it is not compatible with 5GHz.&#039;&#039;&lt;br /&gt;
* Edit aiko_engine_mp/configuration/net.py and insert the details of your SSID and password.&lt;br /&gt;
* use mpfshell: &amp;lt;code&amp;gt;mpfshell -o COM3&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;put configuration/net.py configuration/net.py&amp;lt;/code&amp;gt;&lt;br /&gt;
* fire up repl to view the console log &lt;br /&gt;
* You can now restart your device&lt;br /&gt;
* On bootup it should now talk to your network and you can see it on the console log.&lt;br /&gt;
&lt;br /&gt;
On bootup you should now see...&lt;br /&gt;
&lt;br /&gt;
= Running pre-installed applications =&lt;br /&gt;
&lt;br /&gt;
== Aiko&#039;s minimal Swagbadge application ==&lt;br /&gt;
At the moment the badge by default a basic &amp;quot;Swagbadge&amp;quot; application within the Aiko framework. This application&lt;br /&gt;
* has a thread to keep wifi running, &lt;br /&gt;
* has a thread to stay connected to (our Australian, private) mqtt server&lt;br /&gt;
* has a thread to display a rotating header across the two oleds.&lt;br /&gt;
&lt;br /&gt;
You can now talk to your badge [[Swagbadge2021_MQTT|using MQTT messages]].&lt;br /&gt;
&lt;br /&gt;
== Running other applications ==&lt;br /&gt;
At the moment, &amp;quot;swagbadge&amp;quot; is the only application that&#039;s for use with the badge. &lt;br /&gt;
&lt;br /&gt;
There are [https://github.com/geekscape/aiko_engine_mp/tree/master/applications other applications] in the repo which are for other places the Aiko framework has been used.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve written an application of your own and want to run that by default on badge startup, &lt;br /&gt;
# edit your local copy of configuration/main.py and change the value of the &amp;quot;application&amp;quot; to point to your new application.&lt;br /&gt;
# using mpfshell, &#039;put&#039; configuration/main.py and applications/your_application.py onto the badge&lt;br /&gt;
# Restart the badge&lt;br /&gt;
&lt;br /&gt;
== Running example code ==&lt;br /&gt;
There is [https://github.com/geekscape/aiko_engine_mp/tree/master/examples example code] which has a number of examples in it, including a snake game and a demo of how to use various badge functions.&lt;br /&gt;
&lt;br /&gt;
# From your commandline on your computer, use mpfshell to put whatever example code you want onto the badge.&lt;br /&gt;
# To run example code, you can use the &amp;quot;emergency stop&amp;quot; function to halt any other applications and put you in the repl.&lt;br /&gt;
## Touch both of the bottom spots on the sliders&lt;br /&gt;
## Reboot the badge&lt;br /&gt;
# Now at the repl prompt, type (replace the name of the module as appropriate for the code you want to run): &lt;br /&gt;
&lt;br /&gt;
Use examples.game_snake as example:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
from examples.game_snake import run&lt;br /&gt;
run()&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ctrl-c to halt operation and return to the repl prompt.&lt;br /&gt;
&lt;br /&gt;
= Hardware pinout =&lt;br /&gt;
&lt;br /&gt;
You can get the schematic and pin mapping on this page: https://github.com/CCHS-Melbourne/Swag-Badge/blob/master/swag-badge-schematic.pdf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- GPIO0 : left breakout pin4&lt;br /&gt;
- GPIO2 : left breakout pin3&lt;br /&gt;
&lt;br /&gt;
- GPIO4 : SCL (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO5 : SDA (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO12/15: slider #1&lt;br /&gt;
- GPIO13: left breakout pin3&lt;br /&gt;
- GPIO14/27: slider #2&lt;br /&gt;
- GPIO16: left switch  (under screen #1)&lt;br /&gt;
- GPIO17: right switch (under screen #2)&lt;br /&gt;
&lt;br /&gt;
- GPIO18: SAO3 pin3 + LB pin7&lt;br /&gt;
- GPIO23: SAO3 pin4&lt;br /&gt;
&lt;br /&gt;
- GPIO19: SAO1 pin4&lt;br /&gt;
- GPIO22: SAO1 pin3 (also onboard blue LED in the back)&lt;br /&gt;
&lt;br /&gt;
- GPIO21: unused but not wired on this chip&lt;br /&gt;
&lt;br /&gt;
- GPIO25: SAO4 pin4 + RB pin6&lt;br /&gt;
- GPIO26: SAO4 pin3 + RB pin7&lt;br /&gt;
&lt;br /&gt;
- GPIO27: free (pin available on the chip, not routed anywhere)&lt;br /&gt;
&lt;br /&gt;
- GPIO32: SAO2 pin3 + RB pin4 (touch pin, can be used with SAO tux foot or nose touchpad) &lt;br /&gt;
- GPIO33: SAO2 pin4 + RB pin5 (touch pin, can be used with SAO tux foot or nose touchpad)&lt;br /&gt;
&lt;br /&gt;
- GPIO34: right breakout pin2 (input only)&lt;br /&gt;
- GPIO35: right breakout pin3 (input only)&lt;br /&gt;
&lt;br /&gt;
- GPIO36: unused but not wired on this chip (input only)&lt;br /&gt;
- GPIO39: unused but not wired on this chip (input only)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Extensions: Adding a SAO =&lt;br /&gt;
* provided by others&lt;br /&gt;
* build your own (linky here to our docs)&lt;br /&gt;
&lt;br /&gt;
= Extensions: Updating the software framework =&lt;br /&gt;
&lt;br /&gt;
Between when we ship the board and when it arrives, there might be some changes to the software framework (Aiko). Here&#039;s how to update it. Or perhaps you&#039;re interested in writing your own applications? &lt;br /&gt;
&lt;br /&gt;
* [[Swagbadge2021_UpdatingSoftware|Updating the Software]]&lt;br /&gt;
* [[Swagbadge2021_SoftwareDev|Writing your own badge programs]]&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1304</id>
		<title>Swagbadge2021 GettingStarted</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1304"/>
		<updated>2021-01-19T23:15:30Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Hardware pinout */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Getting started with the Swagbadge =&lt;br /&gt;
&lt;br /&gt;
== Support ==&lt;br /&gt;
* The [https://spectrum.chat/lca2021-swagbadge Swag Badge Spectrum chat] is a place where the badge team hangs out, ready to answer your questions.&lt;br /&gt;
&lt;br /&gt;
== My package arrived in the mail, first steps. ==&lt;br /&gt;
* Your package should contain your badge, and some other goodies! &lt;br /&gt;
** [[File:swagbadgepackage.jpg|400px|alt=Image showing the contents of the swagbag package]]&lt;br /&gt;
** Badge&lt;br /&gt;
** SAO headers (x 4)&lt;br /&gt;
** SAO proto boards (x 2)&lt;br /&gt;
** SAO tux board&lt;br /&gt;
** Lanyard&lt;br /&gt;
** Stickers&lt;br /&gt;
** Instructions&lt;br /&gt;
* Take off the protective cases to reveal the screens.&lt;br /&gt;
* Powering it up&lt;br /&gt;
** Insert a micro USB cable into the badge and connect the other end to a USB port on your computer or USB power source.&lt;br /&gt;
** A green light should glow on the rear of the board, and a title appear across the two screens.&lt;br /&gt;
* Turning it on and off again&lt;br /&gt;
** Plugging/unplugging it is fine. Usually the badge isn&#039;t running anything intensely enough that just unpowering it would cause a problem.&lt;br /&gt;
* On bootup, you should see:&lt;br /&gt;
** The OLED screens will display &amp;quot;Aiko&amp;quot; and a version number as a title&lt;br /&gt;
** It will also display something else to tell you to set up your wifi.&lt;br /&gt;
&lt;br /&gt;
== Getting it on your network ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Safety precautions we have provided&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* When using any hardware ordered off the internet, you can&#039;t be quite certain what software might be present on it. Before shipping these badges to you, we reflashed a fresh copy of MicroPython onto the Lolin32.&lt;br /&gt;
* The framework running on the badge is Aiko, which is open source.&lt;br /&gt;
* The software on the badge is available on the CCHS repository, also all open source.&lt;br /&gt;
* The badges are designed to communicate over MQTT - a lightweight standard for messaging on IoT devices, but we are aware of privacy considerations: you don&#039;t want anybody able to control your badge from afar. The swagbadge protocol provides support for encrypted messages.&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - wireless ===&lt;br /&gt;
&lt;br /&gt;
* The first time you boot your device, it won&#039;t know how to talk to your network. If it can&#039;t detect a pre-existing set of network credentials, or connect to anything it knows about, it will establish a temporary access point and prompt you to navigate to it to enter your wifi details.&lt;br /&gt;
* &#039;&#039;Note: Your device can only talk to a 2.4GHz network: it is not compatible with 5GHz WiFi.&#039;&#039;&lt;br /&gt;
* The screens on your badge will say: &amp;lt;code&amp;gt;Configure WiFi: aiko1234a12341234. Try http://192.168.4.1&amp;lt;/code&amp;gt;&lt;br /&gt;
* Use your phone or computer to connect to the wifi network on the badge. Its name starts with &amp;lt;code&amp;gt;aiko&amp;lt;/code&amp;gt; followed by some numbers/letters.&lt;br /&gt;
* Once you&#039;re connected to the badge, open a web browser to the IP address on the screens. Something like &amp;lt;code&amp;gt;http://192.168.4.1&amp;lt;/code&amp;gt;&lt;br /&gt;
* You&#039;ll be prompted to enter your wifi SSID and wifi password.&lt;br /&gt;
* Once you&#039;ve saved that, the badge will restart using the credentials you&#039;ve provided and it will shut down its wifi access point.&lt;br /&gt;
&lt;br /&gt;
Note: If you are using an Android device to link the badge to your WiFi, it will pop up a dialog to say you are switching to a network that doesn&#039;t have Internet access and ask if you want to switch back. Select &amp;quot;Keep&amp;quot; to stay on the badge&#039;s temporary access point.&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - commandline with mpfshell ===&lt;br /&gt;
&lt;br /&gt;
* If setting up via the wifi AP (access point) doesn&#039;t work, you can put a configuration file onto the badge.&lt;br /&gt;
* You&#039;ll need to start by getting [[Swagbadge2021_UpdatingSoftware|a copy of the aiko firmware, and installing mpfshell]]&lt;br /&gt;
* &#039;&#039;Note: Your device can only talk to a 2.4GHz network: it is not compatible with 5GHz.&#039;&#039;&lt;br /&gt;
* Edit aiko_engine_mp/configuration/net.py and insert the details of your SSID and password.&lt;br /&gt;
* use mpfshell: &amp;lt;code&amp;gt;mpfshell -o COM3&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;put configuration/net.py configuration/net.py&amp;lt;/code&amp;gt;&lt;br /&gt;
* fire up repl to view the console log &lt;br /&gt;
* You can now restart your device&lt;br /&gt;
* On bootup it should now talk to your network and you can see it on the console log.&lt;br /&gt;
&lt;br /&gt;
On bootup you should now see...&lt;br /&gt;
&lt;br /&gt;
= Running pre-installed applications =&lt;br /&gt;
&lt;br /&gt;
== Aiko&#039;s minimal Swagbadge application ==&lt;br /&gt;
At the moment the badge by default a basic &amp;quot;Swagbadge&amp;quot; application within the Aiko framework. This application&lt;br /&gt;
* has a thread to keep wifi running, &lt;br /&gt;
* has a thread to stay connected to (our Australian, private) mqtt server&lt;br /&gt;
* has a thread to display a rotating header across the two oleds.&lt;br /&gt;
&lt;br /&gt;
You can now talk to your badge [[Swagbadge2021_MQTT|using MQTT messages]].&lt;br /&gt;
&lt;br /&gt;
== Running other applications ==&lt;br /&gt;
At the moment, &amp;quot;swagbadge&amp;quot; is the only application that&#039;s for use with the badge. &lt;br /&gt;
&lt;br /&gt;
There are [https://github.com/geekscape/aiko_engine_mp/tree/master/applications other applications] in the repo which are for other places the Aiko framework has been used.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve written an application of your own and want to run that by default on badge startup, &lt;br /&gt;
# edit your local copy of configuration/main.py and change the value of the &amp;quot;application&amp;quot; to point to your new application.&lt;br /&gt;
# using mpfshell, &#039;put&#039; configuration/main.py and applications/your_application.py onto the badge&lt;br /&gt;
# Restart the badge&lt;br /&gt;
&lt;br /&gt;
== Running example code ==&lt;br /&gt;
There is [https://github.com/geekscape/aiko_engine_mp/tree/master/examples example code] which has a number of examples in it, including a snake game and a demo of how to use various badge functions.&lt;br /&gt;
&lt;br /&gt;
# From your commandline on your computer, use mpfshell to put whatever example code you want onto the badge.&lt;br /&gt;
# To run example code, you can use the &amp;quot;emergency stop&amp;quot; function to halt any other applications and put you in the repl.&lt;br /&gt;
## Touch both of the bottom spots on the sliders&lt;br /&gt;
## Reboot the badge&lt;br /&gt;
# Now at the repl prompt, type (replace the name of the module as appropriate for the code you want to run): &lt;br /&gt;
&lt;br /&gt;
Use examples.game_snake as example:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
from examples.game_snake import run&lt;br /&gt;
run()&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ctrl-c to halt operation and return to the repl prompt.&lt;br /&gt;
&lt;br /&gt;
= Hardware pinout =&lt;br /&gt;
&lt;br /&gt;
You can get the schematic and pin mapping on this page: https://github.com/CCHS-Melbourne/Swag-Badge/blob/master/swag-badge-schematic.pdf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- GPIO0 : left breakout pin4&lt;br /&gt;
- GPIO2 : left breakout pin3&lt;br /&gt;
&lt;br /&gt;
- GPIO4 : SCL (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO5 : SDA (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO12/15: slider #1&lt;br /&gt;
- GPIO13: left breakout pin3&lt;br /&gt;
- GPIO14/27: slider #2&lt;br /&gt;
- GPIO16: left switch  (under screen #1)&lt;br /&gt;
- GPIO17: right switch (under screen #2)&lt;br /&gt;
&lt;br /&gt;
- GPIO18: SAO3 pin3 + LB pin7&lt;br /&gt;
- GPIO23: SAO3 pin4&lt;br /&gt;
&lt;br /&gt;
- GPIO19: SAO1 pin4&lt;br /&gt;
- GPIO22: SAO1 pin3 (also onboard blue LED in the back)&lt;br /&gt;
&lt;br /&gt;
- GPIO21: unused but not wired on this chip&lt;br /&gt;
&lt;br /&gt;
- GPIO25: SAO4 pin4 + RB pin6&lt;br /&gt;
- GPIO26: SAO4 pin3 + RB pin7&lt;br /&gt;
&lt;br /&gt;
- GPIO27: free&lt;br /&gt;
&lt;br /&gt;
- GPIO32: SAO2 pin3 + RB pin4 (touch pin, can be used with SAO tux foot or nose touchpad)&lt;br /&gt;
- GPIO33: SAO2 pin4 + RB pin5 (touch pin, can be used with SAO tux foot or nose touchpad)&lt;br /&gt;
&lt;br /&gt;
- GPIO34: right breakout pin2 (input only)&lt;br /&gt;
- GPIO35: right breakout pin3 (input only)&lt;br /&gt;
&lt;br /&gt;
- GPIO36: unused but not wired on this chip (input only)&lt;br /&gt;
- GPIO39: unused but not wired on this chip (input only)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Extensions: Adding a SAO =&lt;br /&gt;
* provided by others&lt;br /&gt;
* build your own (linky here to our docs)&lt;br /&gt;
&lt;br /&gt;
= Extensions: Updating the software framework =&lt;br /&gt;
&lt;br /&gt;
Between when we ship the board and when it arrives, there might be some changes to the software framework (Aiko). Here&#039;s how to update it. Or perhaps you&#039;re interested in writing your own applications? &lt;br /&gt;
&lt;br /&gt;
* [[Swagbadge2021_UpdatingSoftware|Updating the Software]]&lt;br /&gt;
* [[Swagbadge2021_SoftwareDev|Writing your own badge programs]]&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_UpdatingSoftware&amp;diff=1303</id>
		<title>Swagbadge2021 UpdatingSoftware</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_UpdatingSoftware&amp;diff=1303"/>
		<updated>2021-01-19T19:24:23Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Updating the software framework =&lt;br /&gt;
&lt;br /&gt;
Swagbadge owners might want to update the software framework (Aiko). Dagbadge owners will need to put the framework onto their badge before they can use it.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s how to do that!&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
* #swagbadge or #dagbadge or any ESP32 with an OLED screen&lt;br /&gt;
* Micro-USB cable&lt;br /&gt;
* Linux, Mac OS or Linux system running Python 3&lt;br /&gt;
* Command line tools: git&lt;br /&gt;
&lt;br /&gt;
== Setting up your Windows 10 system for connecting to badge hardware ==&lt;br /&gt;
&lt;br /&gt;
How to find your serial COM port on Windows: &lt;br /&gt;
* Use the Device Manager. &lt;br /&gt;
* Under the &amp;quot;Ports&amp;quot; category, you&#039;ll see one or more entries. Hopefully one of which is your badge! It will tell you what Port it is on. &lt;br /&gt;
* If you can&#039;t see your badge, you might need to go up to the View menu and use &amp;quot;Show hidden devices&amp;quot; and see if that helps.&lt;br /&gt;
&lt;br /&gt;
Windows 10 may automatically discover your #swagbadge USB hardware and automatically install the correct USB serial hardware driver, or if nothing still shows up, you might need to update your USB drivers for supporting the USB hardware CP210x on your #swagbadge, please follow these instructions:&lt;br /&gt;
* Download the CP210x drivers from [https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers Silicon Labs Windows Universal Driver]&lt;br /&gt;
* Unpack the zip file&lt;br /&gt;
* Follow the Silicon Labs instructions for [https://www.silabs.com/documents/public/application-notes/AN335.pdf INF only install] (Section 5 on page 9)&lt;br /&gt;
&lt;br /&gt;
By this point, you have know the serial COM port that your #swagbadge is connected to, e.g COM4&lt;br /&gt;
&lt;br /&gt;
== Setting up your Mac OS system for connecting to #swagbadge hardware ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How to find your serial COM port on OS X: &lt;br /&gt;
&lt;br /&gt;
    $ ls /dev/tty.usb*&lt;br /&gt;
&lt;br /&gt;
Unless you have lot of dev boards (or maybe a phone) plugged in you should just see a single filename there.&lt;br /&gt;
Use this (without the `/dev/` prefix) when using the `open` command in `mpfshell`&lt;br /&gt;
&lt;br /&gt;
To get a working `mpfshell` install a recent version of Python (Python3.8 is known to work) using a installed DMG.&lt;br /&gt;
Then create a *venv* and install the necessary tools using pip.&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
    $ mkdir swag&lt;br /&gt;
    $ cd swag&lt;br /&gt;
    $ python3.8 -m venv env&lt;br /&gt;
    $ ./env/bin/pip install esptool mpfshell&lt;br /&gt;
&lt;br /&gt;
You can then run `mpfshell` to connect:&lt;br /&gt;
&lt;br /&gt;
    $ ./env/bin/mpfshell&lt;br /&gt;
    mpfs [/]&amp;gt; open &amp;lt;your device node as found previously&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setting up your Linux system for connecting to #swagbadge hardware ==&lt;br /&gt;
[Link other instructions here]&lt;br /&gt;
&lt;br /&gt;
== Setting up your Windows 10 system for installing #swagbadge firmware == &lt;br /&gt;
&lt;br /&gt;
* Install [https://docs.conda.io/en/latest/miniconda.html Miniconda3] to create a specific Python development environment. (Note we are using Python3 not Python2)&lt;br /&gt;
* Create specific Python 3 environment for playing around with your #swagbadge&lt;br /&gt;
** Start an Anaconda Powershell Prompt (aka Windows Terminal)&lt;br /&gt;
** &amp;lt;code&amp;gt;conda create --yes -n swagbadge python=3&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;conda activate swagbadge&amp;lt;/code&amp;gt;&lt;br /&gt;
* Your command prompt should now look like: &amp;lt;code&amp;gt;(swagbadge) C:\Users\[Username]&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Install some python tools to let us prepare and communicate with the badge&lt;br /&gt;
** &amp;lt;code&amp;gt;pip install esptool mpfshell&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To test that the required tools are installed, trying running the following commands&lt;br /&gt;
** &amp;lt;code&amp;gt;esptool&amp;lt;/code&amp;gt;  # Should show you help on running the esptool&lt;br /&gt;
** &amp;lt;code&amp;gt;mpfshell&amp;lt;/code&amp;gt;  # Should show three lines of output&lt;br /&gt;
*** &amp;lt;code&amp;gt;exit&amp;lt;/code&amp;gt;  #  To exit mpfshell&lt;br /&gt;
&lt;br /&gt;
== Download #swagbadge (Aiko Engine) firmware ==&lt;br /&gt;
&lt;br /&gt;
Within your Anaconda Prompt session, change directory to where you’d like the #swagbadge software to be downloaded, for example:&lt;br /&gt;
* &amp;lt;code&amp;gt;cd $HOME/software&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Download #swagbadge firmware:&lt;br /&gt;
* &amp;lt;code&amp;gt;git clone https://github.com/geekscape/aiko_engine_mp.git&amp;lt;/code&amp;gt; # NOTE: this URL will change once we&#039;re live&lt;br /&gt;
* &amp;lt;code&amp;gt;cd aiko_engine_mp&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Install MicroPython&lt;br /&gt;
* Create a directory to hold the MicroPython firmware, such as aiko_engine_mp/firmware/&lt;br /&gt;
* &amp;lt;code&amp;gt;mkdir firmware&amp;lt;/code&amp;gt;&lt;br /&gt;
* Using your web browser, download: [http://micropython.org/resources/firmware/esp32-idf4-20200902-v1.13.bin esp32-idf4-20200902-v1.13.bin] (mouse right button click → [Save As …]  saving the MicroPython firmware in the firmware directory you just made.&lt;br /&gt;
** The [http://micropython.org/download/ MicroPython download list] has a link to a bunch of firmware drivers, we are using the one for the esp32 device, with the latest 1.4 generic&lt;br /&gt;
&lt;br /&gt;
Erase #swagbadge LoLin-Lite ESP32 flash memory&lt;br /&gt;
* &amp;lt;code&amp;gt;esptool --chip esp32 --port COM3 erase_flash&amp;lt;/code&amp;gt; # adjust the port to suit.&lt;br /&gt;
* You’ll know it’s worked, if the output finishes with “Hard resetting via RTS pin…”&lt;br /&gt;
&lt;br /&gt;
Install microPython on the badge&lt;br /&gt;
* &amp;lt;code&amp;gt;esptool --chip esp32 --port COM3 --baud 460800 write_flash -z 0x1000 firmware\esp32-idf4-20200902-v1.13.bin&amp;lt;/code&amp;gt; #adjust port and firmware location if necessary&lt;br /&gt;
* You’ll know it’s worked, if the output finishes with “Hard resetting via RTS pin…”&lt;br /&gt;
&lt;br /&gt;
Test that the software is installed correctly by using mpfshell&lt;br /&gt;
* &amp;lt;code&amp;gt;mpfshell -o COM3&amp;lt;/code&amp;gt; # Adjust port to suit&lt;br /&gt;
* If it has made a connection to your badge, you will see it say&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;Connected to esp32&lt;br /&gt;
** Micropython File Shell v0.9.1, sw@kaltpost.de **&lt;br /&gt;
-- Running on Python 3.8 using PySerial 3.4 --&lt;br /&gt;
mpfs [/]&amp;gt; &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using mpfshell ==&lt;br /&gt;
&lt;br /&gt;
mpfshell has two functions: it lets you put files on/off the device, and it can give you a python shell to execute code on the device.&lt;br /&gt;
* Getting files on/off the device is a bit like commandline ftp&lt;br /&gt;
** ls - looks at the files on your micropython device&lt;br /&gt;
** lls - looks at the files on your local computer in the current directory&lt;br /&gt;
** put - puts a file to the device&lt;br /&gt;
** cat - shows you the contents of the file&lt;br /&gt;
** help() - gives you more information on the commands&lt;br /&gt;
** repl - opens up the python shell on the badge&lt;br /&gt;
&lt;br /&gt;
Note: To get out of repl, use Ctrl-Q (on Windows) which drops you back into mpfshell&lt;br /&gt;
&lt;br /&gt;
A little program to say hello world!&lt;br /&gt;
* &amp;lt;code&amp;gt; &amp;gt;&amp;gt;&amp;gt; print(&amp;quot;hello world&amp;quot;)&amp;lt;/code&amp;gt;&lt;br /&gt;
* Output: &amp;lt;code&amp;gt;hello world&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A little program to turn the blue light on the board on and off (this is on the underside of the Swagbadge, visible through a circular cutout)&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&amp;gt;&amp;gt;&amp;gt; import machine&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; pin22=machine.Pin(22, machine.Pin.OUT, machine.Pin.PULL_UP)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; pin22.value(0) &lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; pin22.value(1)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Alternatives to mpfshell: rshell and pyboard.py ==&lt;br /&gt;
&lt;br /&gt;
rshell is an option, but it may not be reliable in all cases. However &#039;pip install rshell&#039; also installs pyboard.&lt;br /&gt;
&lt;br /&gt;
pyboard.py is the official tool that ships with micropython and is more flexible and reliable: http://docs.micropython.org/en/latest/reference/pyboard.py.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sauron [mc]$ pyboard.py --device /dev/ttyUSB0 -c &#039;import os; print(os.statvfs(&amp;quot;/&amp;quot;)[0]*os.statvfs(&amp;quot;/&amp;quot;)[3], &amp;quot;bytes free out of&amp;quot;,os.statvfs(&amp;quot;/&amp;quot;)[1]*os.statvfs(&amp;quot;/&amp;quot;)[2])&#039;&lt;br /&gt;
1699840 bytes free out of 2097152&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Saving your private key ==&lt;br /&gt;
&lt;br /&gt;
Use mpfshell to get the file: `configuration/keys.db`.&lt;br /&gt;
&lt;br /&gt;
== Putting the Aiko framework onto the device, using mpfshell == &lt;br /&gt;
* &amp;lt;code&amp;gt;mpfshell COM5 -s scripts\aiko.mpf&amp;lt;/code&amp;gt; #run from within the aiko_framework_mp directory&lt;br /&gt;
&lt;br /&gt;
=== Windows only: Patch mpfshell ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note!&#039;&#039; mpfshell needs a patch applied to let it run a script under Windows.&lt;br /&gt;
&lt;br /&gt;
* Inside &amp;lt;code&amp;gt;C:/users/USERNAME/Miniconda2/envs/swagbadge/Lib/site-packages/mp&amp;lt;/code&amp;gt;&lt;br /&gt;
* edit &amp;lt;code&amp;gt;mpfshell.py&amp;lt;/code&amp;gt;&lt;br /&gt;
* Search for &amp;lt;code&amp;gt;elif args.script is not None:&amp;lt;/code&amp;gt;, around line 796&lt;br /&gt;
* between that line and the next, insert two lines. It should look like:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
    elif args.script is not None:&lt;br /&gt;
&lt;br /&gt;
        if platform.system() == &amp;quot;Windows&amp;quot;:  #INSERT THIS LINE&lt;br /&gt;
            mpfs.use_rawinput = True        #INSERT THIS LINE&lt;br /&gt;
&lt;br /&gt;
        f = open(args.script, &amp;quot;r&amp;quot;)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* Python is very particular about spacing. The rest of the code uses 4 spaces for indents so follow suit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Software development =&lt;br /&gt;
&lt;br /&gt;
See [[Swagbadge2021_SoftwareDev]]&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_SoftwareDev&amp;diff=1302</id>
		<title>Swagbadge2021 SoftwareDev</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_SoftwareDev&amp;diff=1302"/>
		<updated>2021-01-17T23:03:19Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* OLED screens */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:Badge Software Development}}&lt;br /&gt;
&lt;br /&gt;
Want to write your own programs to run on your badge? This page gives a brief overview of the software architecture, an example of a program, and a reference guide on how to access the hardware.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;float:right&amp;quot;&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
The badge runs [https://micropython.org MicroPython] (written by [http://dpgeorge.net/ Damien George] from Melbourne!) and has the [https://github.com/geekscape/aiko_engine_mp Aiko framework] (written by OHMC&#039;s [https://twitter.com/geekscape Andy Gelme]) loaded on it.&lt;br /&gt;
&lt;br /&gt;
MicroPython gives you libraries to access the ESP32 microprocessor functionality. Things like: reading and writing to specific pins on the processor or performing operating system functions such as accessing the file system).&lt;br /&gt;
&lt;br /&gt;
Aiko gives you convenience libraries for driving the badge hardware like the OLED screens, as well as running threads to keep your badge connected to wifi, a connection to the MQTT server, the emergency-stop function to prevent runaway code, and an automatic upgrade function so we can ship upgrades to your device without you having to wrangle git.&lt;br /&gt;
&lt;br /&gt;
== Sample code ==&lt;br /&gt;
&lt;br /&gt;
This code writes &amp;quot;Hello world&amp;quot; to one screen, while displaying the status of the wifi, MQTT connection, button presses and slider status on the left hand screen.&lt;br /&gt;
&lt;br /&gt;
It demonstrates how to use the Aiko event loop to periodically poll for hardware state, as well as how to access some of the features of the badge.&lt;br /&gt;
&lt;br /&gt;
You can find more example code in the &#039;&#039;&#039;examples&#039;&#039;&#039; directory of the [https://github.com/geekscape/aiko_engine_mp/tree/master/examples Aiko repository] on github.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot; style=&amp;quot;overflow:auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;font-weight:bold;line-height:1.6;&amp;quot;&amp;gt;Example code: use &amp;quot;expand&amp;quot; to view&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;nowiki&amp;gt;&lt;br /&gt;
# examples/helloworld.py&lt;br /&gt;
#&lt;br /&gt;
# Writes a message to the oled and displays some state info&lt;br /&gt;
#&lt;br /&gt;
# Usage&lt;br /&gt;
# ~~~~~&lt;br /&gt;
# import examples.helloworld as helloworld&lt;br /&gt;
# from examples.helloworld import run&lt;br /&gt;
# run()&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
from machine import Pin, TouchPad&lt;br /&gt;
import aiko.event as event&lt;br /&gt;
import aiko.oled as oled&lt;br /&gt;
&lt;br /&gt;
title = &amp;quot;Hello!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
import configuration.main&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Buttons: underneath the screens&lt;br /&gt;
button_right = Pin(17, Pin.IN, Pin.PULL_UP)&lt;br /&gt;
button_left = Pin(16, Pin.IN, Pin.PULL_UP)&lt;br /&gt;
&lt;br /&gt;
# Clean out the whole line that was there before&lt;br /&gt;
# Write some new text and show it&lt;br /&gt;
def oled_write_line(oled_target, x, y, text):&lt;br /&gt;
    oled_target.fill_rect(0,y,oled.width, oled.font_size, oled.bg)&lt;br /&gt;
    oled_target.text(text, x, y)&lt;br /&gt;
    oled_target.show()&lt;br /&gt;
    &lt;br /&gt;
def status():&lt;br /&gt;
    sliders = touch_slider_handler()&lt;br /&gt;
    oledL = oled.oleds[0]&lt;br /&gt;
    oledR = oled.oleds[1]&lt;br /&gt;
    oled.write_line(oledR, 1, 10, &amp;quot;Hello world!&amp;quot;)&lt;br /&gt;
    oled_write_line(oledL, 1, 10, &amp;quot;Wifi: &amp;quot;+str(net.is_connected()))&lt;br /&gt;
    oled_write_line(oledL, 1, 20, &amp;quot;MQTT: &amp;quot;+str(mqtt.is_connected()))&lt;br /&gt;
    oled_write_line(oledL, 1, 30, &amp;quot; &amp;quot;+str(int(not(buttonL.value())))+&amp;quot; Button &amp;quot;+str(int(not(buttonR.value()))))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Check on the status of the badge hardware and display that every 500ms          &lt;br /&gt;
def run():&lt;br /&gt;
    oled.oleds_clear(oled.bg)&lt;br /&gt;
    oled.set_title(title)&lt;br /&gt;
    event.add_timer_handler(status, 500)&lt;br /&gt;
    try:&lt;br /&gt;
        event.loop()&lt;br /&gt;
    finally:&lt;br /&gt;
        event.remove_timer_handler(statusbar)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of a Swagbadge application ==&lt;br /&gt;
&lt;br /&gt;
An application runs when the Aiko framework is also running, so you can rely on having all the badge services available.&lt;br /&gt;
&lt;br /&gt;
An application is designed to be triggered when the badge is rebooted (either via pushing the button on the back, or via using ^D in the repl). The badge knows which application to run by the state of the &amp;lt;code&amp;gt;configuration\main.py&amp;lt;/code&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
The framework will call your application&#039;s &#039;&#039;&#039;initialise()&#039;&#039;&#039; function. The framework is running an event loop, so the initialise function is the place to add in event handlers to respond to actions you take on the badge.&lt;br /&gt;
&lt;br /&gt;
{{Note|Note: Refreshing the OLEDs is reasonably intense on the microprocessor. If you have too many event loops triggering too often and/or too much screen activity, you can starve the badge of resources. This can produce wifi dropouts, or non-responsiveness. If you have a lot of screen activity, consider using a buffer or recording state and just doing a screen update periodically}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Software reference ==&lt;br /&gt;
&lt;br /&gt;
=== MicroPython environment ===&lt;br /&gt;
&lt;br /&gt;
[https://micropython.org MicroPython docs]&lt;br /&gt;
&lt;br /&gt;
==== Special files ====&lt;br /&gt;
&lt;br /&gt;
There are two special files which are run automatically by MicroPython if they exist on the filesystem: &amp;lt;code&amp;gt;boot.py&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;boot.py&#039;&#039;&#039;: This file is run first on power up/reset. We don&#039;t modify it from what MicroPython ships with, but it&#039;s important to know it exists (and not to delete it), and is interesting to look into it to see what it does.&lt;br /&gt;
* &#039;&#039;&#039;main.py&#039;&#039;&#039;: This is run after boot.py so if you want something to automatically happen on boot/reset, this is where to put it. We use this to start up the Aiko framework, initialise the hardware (such as the network and mqtt) and start up any application that is configured inside &amp;lt;code&amp;gt;configuration/main.py&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Directory structure ====&lt;br /&gt;
&lt;br /&gt;
What&#039;s on the processor? Where does it live?&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;main.py&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;boot.py&amp;lt;/code&amp;gt; - files run on bootup&lt;br /&gt;
* &amp;lt;code&amp;gt;lib&amp;lt;/code&amp;gt; - code in here is aiko framework code and automatically in the micropython &#039;path&#039;.&lt;br /&gt;
** &amp;lt;code&amp;gt;aiko&amp;lt;/code&amp;gt; - the aiko framework&lt;br /&gt;
* &amp;lt;code&amp;gt;applications&amp;lt;/code&amp;gt; - programs to run automatically on bootup. Must have an initialise function&lt;br /&gt;
* &amp;lt;code&amp;gt;configuration&amp;lt;/code&amp;gt; - control the config of aiko using files in here&lt;br /&gt;
* &amp;lt;code&amp;gt;examples&amp;lt;/code&amp;gt; - sample code!&lt;br /&gt;
&lt;br /&gt;
You can&#039;t edit the files directly on the processor (there&#039;s no editing tooling): you edit a copy of it on your computer, then use mpfshell to &amp;lt;code&amp;gt;put&amp;lt;/code&amp;gt; it onto the badge.&lt;br /&gt;
&lt;br /&gt;
For micropython purposes, you can use the &amp;lt;code&amp;gt;import&amp;lt;/code&amp;gt; statement to import anything in the &amp;lt;code&amp;gt;lib&amp;lt;/code&amp;gt; directory without prefacing it with &amp;quot;lib&amp;quot;, anything else is imported from root.&lt;br /&gt;
For example:&lt;br /&gt;
* to import lib/aiko/net.py, you would use &amp;lt;code&amp;gt;import aiko.net&amp;lt;/code&amp;gt;&lt;br /&gt;
* to import examples/showcase.py, you would use &amp;lt;code&amp;gt;import examples.showcase&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because the aiko configuration files are, themselves, just python, you can also do &amp;lt;code&amp;gt;import configuration.main.settings&amp;lt;/code&amp;gt; where the file is in /configuration/main.py but it contains a datastructure called &#039;settings&#039;.&lt;br /&gt;
=== MQTT ===&lt;br /&gt;
&lt;br /&gt;
See [[Swagbadge2021_MQTT]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Software development ==&lt;br /&gt;
&lt;br /&gt;
=== Aiko ===&lt;br /&gt;
The Aiko Engine is what runs after boot (FreeRTOS, then microPython). Aiko provides a framework for developing applications, by providing higher level abstractions over the basic hardware, events, messaging and other conveniences. Basically, a lot of house keeping that you&#039;d end up writing yourself. After boot, there are two background threads, one looking after Wi-Fi connectivity and the other looking after MQTT connectivity.  &lt;br /&gt;
There are also three event handlers: MQTT keep-alive, firmware upgrader and the work-in-progress SwagBadge application handler.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; aiko.event.event_list.print()&lt;br /&gt;
&amp;lt;function swagbadge_handler at 0x3ffe6c70&amp;gt; every 5000 next 23099&lt;br /&gt;
&amp;lt;function upgrade_handler at 0x3ffedfa0&amp;gt; every 5000 next 23099&lt;br /&gt;
&amp;lt;function mqtt_ping_handler at 0x3ffe9820&amp;gt; every 60000 next 73672&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That last handler, which every 5 seconds is updating the title bar &amp;quot;LCA2021&amp;quot; &amp;lt;--&amp;gt; &amp;quot;SwagBadge&amp;quot; (see https://github.com/geekscape/aiko_engine_mp/blob/master/applications/swagbadge.py ).&lt;br /&gt;
&lt;br /&gt;
You can stop a handler, like this (this will stop the top bar status updater):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; import applications.swagbadge&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; aiko.event.remove_timer_handler(application.swagbadge_handler)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Testing code ===&lt;br /&gt;
&lt;br /&gt;
First write your code on your computer, and make sure it compiles ( python -m py_compile code.py )&lt;br /&gt;
&lt;br /&gt;
Then, you can go in repl and use paste mode (^E). It only works if you paste a few lines at a time. End your paste with ^D and then if you pasted a function, call the function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; ^E&lt;br /&gt;
paste mode; Ctrl-C to cancel, Ctrl-D to finish&lt;br /&gt;
=== PASTE_YOUR_CODE_HERE&lt;br /&gt;
=== ^D&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Pushing new code ===&lt;br /&gt;
Occasionally you might find that the updated source code that you just used the mpfshell &amp;quot;put&amp;quot; command to transfer isn&#039;t properly stored on the ESP32 microPython flash filesystem. After rebooting, you might see unexpected errors. A simple way to check is to use the mpfshell &amp;quot;cat&amp;quot; command to check that the file was completely transferred.  &lt;br /&gt;
&lt;br /&gt;
The safest way to update code is to perform a reboot after transferring all the files. Doing a soft-reboot using Control-D doesn&#039;t take long, i.e it is faster and easier than doing a hard-reboot with the reset button. The good thing about a reboot (microPython interpreter restart) is that there is no confusion about the complete state of your system, i.e what references have been held onto from your older source code that might still be running in a thread or as an event handler (via the Aiko Engine framework).&lt;br /&gt;
&lt;br /&gt;
You can also delete all running modules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.modules.clear() &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More details in https://spectrum.chat/lca2021-swagbadge/software/safe-software-updates~ba541e3c-d8a2-41a8-ac47-71d87696de2d&lt;br /&gt;
&lt;br /&gt;
=== Replacing the swagbadge application with your own ===&lt;br /&gt;
&lt;br /&gt;
Edit configuration/main.py and set &amp;quot;application&amp;quot;: &amp;quot;application/yourcode&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Reboot to shell / Force runaway code to stop ===&lt;br /&gt;
&lt;br /&gt;
It&#039;s possible to write code that will leave your badge unresponsive. Rebooting just reruns the same bad code. What to do?&lt;br /&gt;
&lt;br /&gt;
* Place a finger on each of the bottom slider pads, either side of the microprocessor. &lt;br /&gt;
* Trigger a restart by using the button on the back of the badge, or Ctrl-D in repl (if you can get into repl)&lt;br /&gt;
&lt;br /&gt;
The badge will restart but not autorun any code, just drop you back at the repl prompt. From there you can &amp;lt;code&amp;gt;put&amp;lt;/code&amp;gt; bugfixed code back onto the device.&lt;br /&gt;
&lt;br /&gt;
See https://github.com/geekscape/aiko_engine_mp/blob/a5b5593d37509df64a3dcb4cdc3d13a411152d82/main.py#L20&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Hardware reference ==&lt;br /&gt;
&lt;br /&gt;
=== OLED screens ===&lt;br /&gt;
&lt;br /&gt;
==== via MQTT ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;(oled:clear)&#039;&#039;&#039; : clears both screens&lt;br /&gt;
* &#039;&#039;&#039;(oled:log Hello World!)&#039;&#039;&#039; : writes a message along the bottom of the screens, scrolling up whatever is there out of the way&lt;br /&gt;
* &#039;&#039;&#039;(oled:pixel x y)&#039;&#039;&#039; : lights a pixel at that spot&lt;br /&gt;
* &#039;&#039;&#039;(oled:text x y This is a test!)&#039;&#039;&#039; : Puts some text at the position x,y. It will be displayed over the top of whatever&#039;s there.&lt;br /&gt;
&lt;br /&gt;
==== via API ====&lt;br /&gt;
&lt;br /&gt;
On the badge, by default the two oleds work as a single long screen, with text split across both of them. You can access a specific oled and use the underlying functions to write to them&lt;br /&gt;
&lt;br /&gt;
Library&lt;br /&gt;
* &#039;&#039;&#039;from aiko import oled&#039;&#039;&#039; # make the oled functions available for use within your code&lt;br /&gt;
&lt;br /&gt;
Globals&lt;br /&gt;
* &#039;&#039;&#039;[] oled.oleds&#039;&#039;&#039; # an array of oleds, letting you address them separately if you choose&lt;br /&gt;
* &#039;&#039;&#039;int oled.fg/oled.bg&#039;&#039;&#039; # get/set fg and bg colours (0 or 1)&lt;br /&gt;
* &#039;&#039;&#039;int oled.font_size&#039;&#039;&#039; # helpful to work out how much space a line of text will take up&lt;br /&gt;
* &#039;&#039;&#039;boolean oled.lock_title&#039;&#039;&#039; # true/false. True means the display always shows the title. False means it&#039;ll be wiped once the display is cleared.&lt;br /&gt;
&lt;br /&gt;
Functions&lt;br /&gt;
* &#039;&#039;&#039;oled.initialise()&#039;&#039;&#039; # uses configuration.oled.settings by default, normally already invoked by the base swagbadge handler&lt;br /&gt;
* &#039;&#039;&#039;oled.oleds_clear(colour)&#039;&#039;&#039; # pass in oled.bg or oled.fg for easy set. Wipes the display&lt;br /&gt;
* &#039;&#039;&#039;oled.log(text)&#039;&#039;&#039; # scroll up text to insert a new line at the bottom of the display&lt;br /&gt;
* &#039;&#039;&#039;oled.text(text, x, y, colour)&#039;&#039;&#039; # add text at the position x,y in the colour specified. Note: does not clear the contents at this spot first.&lt;br /&gt;
* &#039;&#039;&#039;oled.oleds_show()&#039;&#039;&#039; # refresh the display with the latest text/image additions&lt;br /&gt;
* &#039;&#039;&#039;oled.set_title(text)&#039;&#039;&#039; # set the title text&lt;br /&gt;
* &#039;&#039;&#039;oled.write_title()&#039;&#039;&#039; # write the title text&lt;br /&gt;
&lt;br /&gt;
==== Oled image push and I2C speed ====&lt;br /&gt;
&lt;br /&gt;
- example #1: https://github.com/geekscape/aiko_engine_mp/blob/master/examples/oled_image.py&lt;br /&gt;
&lt;br /&gt;
- example #2: https://github.com/geekscape/aiko_engine_mp/blob/master/examples/oled_benchmark.py&lt;br /&gt;
&lt;br /&gt;
The 2nd example gets a speed of 21fps per screen (or about 10fps for both screens).&lt;br /&gt;
&lt;br /&gt;
Using C++ code (see https://github.com/geekscape/aiko_engine_mp/commit/a22b3099584c9978807e08adf752f3082af65875 ) you get at least 61fps per screen (if you do assembly: 86fps, and with crazy I2C noacks hacks, you can get 150fps: https://bitbanksoftware.blogspot.com/2018/05/fast-ssd1306-oled-drawing-with-i2c-bit.html ).&lt;br /&gt;
&lt;br /&gt;
Back to python, if you increase the CPU speed with  machine.freq(240000000) , you&#039;ll get 26fps per screen, and if you replace the image pixel pushes by a full back or full white push, you get 29fps, which seems to be an upper limit of the python oled code. A better end to end C++ driver could give a lot more speed.&lt;br /&gt;
&lt;br /&gt;
=== Screen buttons ===&lt;br /&gt;
&lt;br /&gt;
If you push (gently!) on the screens, you&#039;ll discover they double as buttons: there&#039;s a small switch under each OLED that is pressed when you push down on the screen.&lt;br /&gt;
&lt;br /&gt;
{{Note|&#039;&#039;&#039;Warning&#039;&#039;&#039;: Push on the &#039;&#039;&#039;middle&#039;&#039;&#039; of the screen, not the edge. This will minimise the risk of bending... and breaking... the screen.}}&lt;br /&gt;
&lt;br /&gt;
The left screen button is pin 16. The right screen button is pin 17.&lt;br /&gt;
&lt;br /&gt;
==== via API ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from machine import Pin&lt;br /&gt;
&lt;br /&gt;
button_left = Pin(16, Pin.IN, Pin.PULL_UP)&lt;br /&gt;
button_right = Pin(17, Pin.IN, Pin.PULL_UP)&lt;br /&gt;
&lt;br /&gt;
pressed = not(button_left.value())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The button sends &amp;quot;1&amp;quot; when it&#039;s &#039;&#039;not&#039;&#039; being pressed, and &amp;quot;0&amp;quot; when it is. This is counterintuitive to most of us, so I recommend inverting the value when reading it.&lt;br /&gt;
&lt;br /&gt;
=== Sliders ===&lt;br /&gt;
&lt;br /&gt;
The sliders operate via capacitive touch. You can use them to detect if someone has their finger on the circular pads at either end (which let you treat them like buttons), or you can detect the position of the finger along the slider by checking the relative values as the capacitance changes.&lt;br /&gt;
&lt;br /&gt;
The left slider is on pins 12 (bottom) and 15 (top), right slider is on pins 14 (bottom) and 27 (top).&lt;br /&gt;
&lt;br /&gt;
More info from MicroPython about [http://docs.micropython.org/en/latest/esp32/quickref.html?highlight=touchpad#capacitive-touch capacitive touch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from machine import Pin, TouchPad&lt;br /&gt;
import aiko.common&lt;br /&gt;
&lt;br /&gt;
bottom_left = TouchPad(Pin(12))&lt;br /&gt;
top_left = TouchPad(Pin(15))&lt;br /&gt;
bottom_right = TouchPad(Pin(14))&lt;br /&gt;
top_right = TouchPad(Pin(27))&lt;br /&gt;
&lt;br /&gt;
# is this button pressed?&lt;br /&gt;
# the commons library returns true/false&lt;br /&gt;
pressed_bottom_left = common.touch_pins_check([bottom_left])&lt;br /&gt;
&lt;br /&gt;
# check where we are along the slider&lt;br /&gt;
# the &#039;read&#039; functions return an integer of the &#039;strength&#039; of the &lt;br /&gt;
# capacitance. As you move your finger between the endpoints, &lt;br /&gt;
#the relative value of the difference between them will change.&lt;br /&gt;
slider_left = bottom_left.read() - bottom_left.read()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Micropython functions&lt;br /&gt;
* &#039;&#039;&#039;touchpad.read()&#039;&#039;&#039; - gives you the current value of the sensor. It will be large when not touched (over 1000) and smaller when touched.&lt;br /&gt;
Aiko functions&lt;br /&gt;
* &#039;&#039;&#039;common.touch_pins_check(touchpad_array)&#039;&#039;&#039; - Returns true if &#039;&#039;all&#039;&#039; the touchpad sensors listed are being touched, false otherwise.&lt;br /&gt;
&lt;br /&gt;
=== SAOs (simple addons) ===&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_SoftwareDev&amp;diff=1301</id>
		<title>Swagbadge2021 SoftwareDev</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_SoftwareDev&amp;diff=1301"/>
		<updated>2021-01-17T01:06:44Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:Badge Software Development}}&lt;br /&gt;
&lt;br /&gt;
Want to write your own programs to run on your badge? This page gives a brief overview of the software architecture, an example of a program, and a reference guide on how to access the hardware.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;float:right&amp;quot;&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
The badge runs [https://micropython.org MicroPython] (written by [http://dpgeorge.net/ Damien George] from Melbourne!) and has the [https://github.com/geekscape/aiko_engine_mp Aiko framework] (written by OHMC&#039;s [https://twitter.com/geekscape Andy Gelme]) loaded on it.&lt;br /&gt;
&lt;br /&gt;
MicroPython gives you libraries to access the ESP32 microprocessor functionality. Things like: reading and writing to specific pins on the processor or performing operating system functions such as accessing the file system).&lt;br /&gt;
&lt;br /&gt;
Aiko gives you convenience libraries for driving the badge hardware like the OLED screens, as well as running threads to keep your badge connected to wifi, a connection to the MQTT server, the emergency-stop function to prevent runaway code, and an automatic upgrade function so we can ship upgrades to your device without you having to wrangle git.&lt;br /&gt;
&lt;br /&gt;
== Sample code ==&lt;br /&gt;
&lt;br /&gt;
This code writes &amp;quot;Hello world&amp;quot; to one screen, while displaying the status of the wifi, MQTT connection, button presses and slider status on the left hand screen.&lt;br /&gt;
&lt;br /&gt;
It demonstrates how to use the Aiko event loop to periodically poll for hardware state, as well as how to access some of the features of the badge.&lt;br /&gt;
&lt;br /&gt;
You can find more example code in the &#039;&#039;&#039;examples&#039;&#039;&#039; directory of the [https://github.com/geekscape/aiko_engine_mp/tree/master/examples Aiko repository] on github.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot; style=&amp;quot;overflow:auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;font-weight:bold;line-height:1.6;&amp;quot;&amp;gt;Example code: use &amp;quot;expand&amp;quot; to view&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;nowiki&amp;gt;&lt;br /&gt;
# examples/helloworld.py&lt;br /&gt;
#&lt;br /&gt;
# Writes a message to the oled and displays some state info&lt;br /&gt;
#&lt;br /&gt;
# Usage&lt;br /&gt;
# ~~~~~&lt;br /&gt;
# import examples.helloworld as helloworld&lt;br /&gt;
# from examples.helloworld import run&lt;br /&gt;
# run()&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
from machine import Pin, TouchPad&lt;br /&gt;
import aiko.event as event&lt;br /&gt;
import aiko.oled as oled&lt;br /&gt;
&lt;br /&gt;
title = &amp;quot;Hello!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
import configuration.main&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Buttons: underneath the screens&lt;br /&gt;
button_right = Pin(17, Pin.IN, Pin.PULL_UP)&lt;br /&gt;
button_left = Pin(16, Pin.IN, Pin.PULL_UP)&lt;br /&gt;
&lt;br /&gt;
# Clean out the whole line that was there before&lt;br /&gt;
# Write some new text and show it&lt;br /&gt;
def oled_write_line(oled_target, x, y, text):&lt;br /&gt;
    oled_target.fill_rect(0,y,oled.width, oled.font_size, oled.bg)&lt;br /&gt;
    oled_target.text(text, x, y)&lt;br /&gt;
    oled_target.show()&lt;br /&gt;
    &lt;br /&gt;
def status():&lt;br /&gt;
    sliders = touch_slider_handler()&lt;br /&gt;
    oledL = oled.oleds[0]&lt;br /&gt;
    oledR = oled.oleds[1]&lt;br /&gt;
    oled.write_line(oledR, 1, 10, &amp;quot;Hello world!&amp;quot;)&lt;br /&gt;
    oled_write_line(oledL, 1, 10, &amp;quot;Wifi: &amp;quot;+str(net.is_connected()))&lt;br /&gt;
    oled_write_line(oledL, 1, 20, &amp;quot;MQTT: &amp;quot;+str(mqtt.is_connected()))&lt;br /&gt;
    oled_write_line(oledL, 1, 30, &amp;quot; &amp;quot;+str(int(not(buttonL.value())))+&amp;quot; Button &amp;quot;+str(int(not(buttonR.value()))))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Check on the status of the badge hardware and display that every 500ms          &lt;br /&gt;
def run():&lt;br /&gt;
    oled.oleds_clear(oled.bg)&lt;br /&gt;
    oled.set_title(title)&lt;br /&gt;
    event.add_timer_handler(status, 500)&lt;br /&gt;
    try:&lt;br /&gt;
        event.loop()&lt;br /&gt;
    finally:&lt;br /&gt;
        event.remove_timer_handler(statusbar)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of a Swagbadge application ==&lt;br /&gt;
&lt;br /&gt;
An application runs when the Aiko framework is also running, so you can rely on having all the badge services available.&lt;br /&gt;
&lt;br /&gt;
An application is designed to be triggered when the badge is rebooted (either via pushing the button on the back, or via using ^D in the repl). The badge knows which application to run by the state of the &amp;lt;code&amp;gt;configuration\main.py&amp;lt;/code&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
The framework will call your application&#039;s &#039;&#039;&#039;initialise()&#039;&#039;&#039; function. The framework is running an event loop, so the initialise function is the place to add in event handlers to respond to actions you take on the badge.&lt;br /&gt;
&lt;br /&gt;
{{Note|Note: Refreshing the OLEDs is reasonably intense on the microprocessor. If you have too many event loops triggering too often and/or too much screen activity, you can starve the badge of resources. This can produce wifi dropouts, or non-responsiveness. If you have a lot of screen activity, consider using a buffer or recording state and just doing a screen update periodically}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Software reference ==&lt;br /&gt;
&lt;br /&gt;
=== MicroPython environment ===&lt;br /&gt;
&lt;br /&gt;
[https://micropython.org MicroPython docs]&lt;br /&gt;
&lt;br /&gt;
==== Special files ====&lt;br /&gt;
&lt;br /&gt;
There are two special files which are run automatically by MicroPython if they exist on the filesystem: &amp;lt;code&amp;gt;boot.py&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;boot.py&#039;&#039;&#039;: This file is run first on power up/reset. We don&#039;t modify it from what MicroPython ships with, but it&#039;s important to know it exists (and not to delete it), and is interesting to look into it to see what it does.&lt;br /&gt;
* &#039;&#039;&#039;main.py&#039;&#039;&#039;: This is run after boot.py so if you want something to automatically happen on boot/reset, this is where to put it. We use this to start up the Aiko framework, initialise the hardware (such as the network and mqtt) and start up any application that is configured inside &amp;lt;code&amp;gt;configuration/main.py&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Directory structure ====&lt;br /&gt;
&lt;br /&gt;
What&#039;s on the processor? Where does it live?&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;main.py&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;boot.py&amp;lt;/code&amp;gt; - files run on bootup&lt;br /&gt;
* &amp;lt;code&amp;gt;lib&amp;lt;/code&amp;gt; - code in here is aiko framework code and automatically in the micropython &#039;path&#039;.&lt;br /&gt;
** &amp;lt;code&amp;gt;aiko&amp;lt;/code&amp;gt; - the aiko framework&lt;br /&gt;
* &amp;lt;code&amp;gt;applications&amp;lt;/code&amp;gt; - programs to run automatically on bootup. Must have an initialise function&lt;br /&gt;
* &amp;lt;code&amp;gt;configuration&amp;lt;/code&amp;gt; - control the config of aiko using files in here&lt;br /&gt;
* &amp;lt;code&amp;gt;examples&amp;lt;/code&amp;gt; - sample code!&lt;br /&gt;
&lt;br /&gt;
You can&#039;t edit the files directly on the processor (there&#039;s no editing tooling): you edit a copy of it on your computer, then use mpfshell to &amp;lt;code&amp;gt;put&amp;lt;/code&amp;gt; it onto the badge.&lt;br /&gt;
&lt;br /&gt;
For micropython purposes, you can use the &amp;lt;code&amp;gt;import&amp;lt;/code&amp;gt; statement to import anything in the &amp;lt;code&amp;gt;lib&amp;lt;/code&amp;gt; directory without prefacing it with &amp;quot;lib&amp;quot;, anything else is imported from root.&lt;br /&gt;
For example:&lt;br /&gt;
* to import lib/aiko/net.py, you would use &amp;lt;code&amp;gt;import aiko.net&amp;lt;/code&amp;gt;&lt;br /&gt;
* to import examples/showcase.py, you would use &amp;lt;code&amp;gt;import examples.showcase&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because the aiko configuration files are, themselves, just python, you can also do &amp;lt;code&amp;gt;import configuration.main.settings&amp;lt;/code&amp;gt; where the file is in /configuration/main.py but it contains a datastructure called &#039;settings&#039;.&lt;br /&gt;
=== MQTT ===&lt;br /&gt;
&lt;br /&gt;
See [[Swagbadge2021_MQTT]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Software development ==&lt;br /&gt;
&lt;br /&gt;
=== Aiko ===&lt;br /&gt;
The Aiko Engine is what runs after boot (FreeRTOS, then microPython). Aiko provides a framework for developing applications, by providing higher level abstractions over the basic hardware, events, messaging and other conveniences. Basically, a lot of house keeping that you&#039;d end up writing yourself. After boot, there are two background threads, one looking after Wi-Fi connectivity and the other looking after MQTT connectivity.  &lt;br /&gt;
There are also three event handlers: MQTT keep-alive, firmware upgrader and the work-in-progress SwagBadge application handler.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; aiko.event.event_list.print()&lt;br /&gt;
&amp;lt;function swagbadge_handler at 0x3ffe6c70&amp;gt; every 5000 next 23099&lt;br /&gt;
&amp;lt;function upgrade_handler at 0x3ffedfa0&amp;gt; every 5000 next 23099&lt;br /&gt;
&amp;lt;function mqtt_ping_handler at 0x3ffe9820&amp;gt; every 60000 next 73672&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That last handler, which every 5 seconds is updating the title bar &amp;quot;LCA2021&amp;quot; &amp;lt;--&amp;gt; &amp;quot;SwagBadge&amp;quot; (see https://github.com/geekscape/aiko_engine_mp/blob/master/applications/swagbadge.py ).&lt;br /&gt;
&lt;br /&gt;
You can stop a handler, like this (this will stop the top bar status updater):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; import applications.swagbadge&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; aiko.event.remove_timer_handler(application.swagbadge_handler)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Testing code ===&lt;br /&gt;
&lt;br /&gt;
First write your code on your computer, and make sure it compiles ( python -m py_compile code.py )&lt;br /&gt;
&lt;br /&gt;
Then, you can go in repl and use paste mode (^E). It only works if you paste a few lines at a time. End your paste with ^D and then if you pasted a function, call the function:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; ^E&lt;br /&gt;
paste mode; Ctrl-C to cancel, Ctrl-D to finish&lt;br /&gt;
=== PASTE_YOUR_CODE_HERE&lt;br /&gt;
=== ^D&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Pushing new code ===&lt;br /&gt;
Occasionally you might find that the updated source code that you just used the mpfshell &amp;quot;put&amp;quot; command to transfer isn&#039;t properly stored on the ESP32 microPython flash filesystem. After rebooting, you might see unexpected errors. A simple way to check is to use the mpfshell &amp;quot;cat&amp;quot; command to check that the file was completely transferred.  &lt;br /&gt;
&lt;br /&gt;
The safest way to update code is to perform a reboot after transferring all the files. Doing a soft-reboot using Control-D doesn&#039;t take long, i.e it is faster and easier than doing a hard-reboot with the reset button. The good thing about a reboot (microPython interpreter restart) is that there is no confusion about the complete state of your system, i.e what references have been held onto from your older source code that might still be running in a thread or as an event handler (via the Aiko Engine framework).&lt;br /&gt;
&lt;br /&gt;
You can also delete all running modules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.modules.clear() &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More details in https://spectrum.chat/lca2021-swagbadge/software/safe-software-updates~ba541e3c-d8a2-41a8-ac47-71d87696de2d&lt;br /&gt;
&lt;br /&gt;
=== Replacing the swagbadge application with your own ===&lt;br /&gt;
&lt;br /&gt;
Edit configuration/main.py and set &amp;quot;application&amp;quot;: &amp;quot;application/yourcode&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Reboot to shell / Force runaway code to stop ===&lt;br /&gt;
&lt;br /&gt;
It&#039;s possible to write code that will leave your badge unresponsive. Rebooting just reruns the same bad code. What to do?&lt;br /&gt;
&lt;br /&gt;
* Place a finger on each of the bottom slider pads, either side of the microprocessor. &lt;br /&gt;
* Trigger a restart by using the button on the back of the badge, or Ctrl-D in repl (if you can get into repl)&lt;br /&gt;
&lt;br /&gt;
The badge will restart but not autorun any code, just drop you back at the repl prompt. From there you can &amp;lt;code&amp;gt;put&amp;lt;/code&amp;gt; bugfixed code back onto the device.&lt;br /&gt;
&lt;br /&gt;
See https://github.com/geekscape/aiko_engine_mp/blob/a5b5593d37509df64a3dcb4cdc3d13a411152d82/main.py#L20&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Hardware reference ==&lt;br /&gt;
&lt;br /&gt;
=== OLED screens ===&lt;br /&gt;
&lt;br /&gt;
==== via MQTT ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;(oled:clear)&#039;&#039;&#039; : clears both screens&lt;br /&gt;
* &#039;&#039;&#039;(oled:log Hello World!)&#039;&#039;&#039; : writes a message along the bottom of the screens, scrolling up whatever is there out of the way&lt;br /&gt;
* &#039;&#039;&#039;(oled:pixel x y)&#039;&#039;&#039; : lights a pixel at that spot&lt;br /&gt;
* &#039;&#039;&#039;(oled:text x y This is a test!)&#039;&#039;&#039; : Puts some text at the position x,y. It will be displayed over the top of whatever&#039;s there.&lt;br /&gt;
&lt;br /&gt;
==== via API ====&lt;br /&gt;
&lt;br /&gt;
On the badge, by default the two oleds work as a single long screen, with text split across both of them. You can access a specific oled and use the underlying functions to write to them&lt;br /&gt;
&lt;br /&gt;
Library&lt;br /&gt;
* &#039;&#039;&#039;from aiko import oled&#039;&#039;&#039; # make the oled functions available for use within your code&lt;br /&gt;
&lt;br /&gt;
Globals&lt;br /&gt;
* &#039;&#039;&#039;[] oled.oleds&#039;&#039;&#039; # an array of oleds, letting you address them separately if you choose&lt;br /&gt;
* &#039;&#039;&#039;int oled.fg/oled.bg&#039;&#039;&#039; # get/set fg and bg colours (0 or 1)&lt;br /&gt;
* &#039;&#039;&#039;int oled.font_size&#039;&#039;&#039; # helpful to work out how much space a line of text will take up&lt;br /&gt;
* &#039;&#039;&#039;boolean oled.lock_title&#039;&#039;&#039; # true/false. True means the display always shows the title. False means it&#039;ll be wiped once the display is cleared.&lt;br /&gt;
&lt;br /&gt;
Functions&lt;br /&gt;
* &#039;&#039;&#039;oled.initialise()&#039;&#039;&#039; # uses configuration.oled.settings by default, normally already invoked by the base swagbadge handler&lt;br /&gt;
* &#039;&#039;&#039;oled.oleds_clear(colour)&#039;&#039;&#039; # pass in oled.bg or oled.fg for easy set. Wipes the display&lt;br /&gt;
* &#039;&#039;&#039;oled.log(text)&#039;&#039;&#039; # scroll up text to insert a new line at the bottom of the display&lt;br /&gt;
* &#039;&#039;&#039;oled.text(text, x, y, colour)&#039;&#039;&#039; # add text at the position x,y in the colour specified. Note: does not clear the contents at this spot first.&lt;br /&gt;
* &#039;&#039;&#039;oled.oleds_show()&#039;&#039;&#039; # refresh the display with the latest text/image additions&lt;br /&gt;
* &#039;&#039;&#039;oled.set_title(text)&#039;&#039;&#039; # set the title text&lt;br /&gt;
* &#039;&#039;&#039;oled.write_title()&#039;&#039;&#039; # write the title text&lt;br /&gt;
&lt;br /&gt;
Coming soon - a way to easily write images to an oled.&lt;br /&gt;
&lt;br /&gt;
=== Screen buttons ===&lt;br /&gt;
&lt;br /&gt;
If you push (gently!) on the screens, you&#039;ll discover they double as buttons: there&#039;s a small switch under each OLED that is pressed when you push down on the screen.&lt;br /&gt;
&lt;br /&gt;
{{Note|&#039;&#039;&#039;Warning&#039;&#039;&#039;: Push on the &#039;&#039;&#039;middle&#039;&#039;&#039; of the screen, not the edge. This will minimise the risk of bending... and breaking... the screen.}}&lt;br /&gt;
&lt;br /&gt;
The left screen button is pin 16. The right screen button is pin 17.&lt;br /&gt;
&lt;br /&gt;
==== via API ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from machine import Pin&lt;br /&gt;
&lt;br /&gt;
button_left = Pin(16, Pin.IN, Pin.PULL_UP)&lt;br /&gt;
button_right = Pin(17, Pin.IN, Pin.PULL_UP)&lt;br /&gt;
&lt;br /&gt;
pressed = not(button_left.value())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The button sends &amp;quot;1&amp;quot; when it&#039;s &#039;&#039;not&#039;&#039; being pressed, and &amp;quot;0&amp;quot; when it is. This is counterintuitive to most of us, so I recommend inverting the value when reading it.&lt;br /&gt;
&lt;br /&gt;
=== Sliders ===&lt;br /&gt;
&lt;br /&gt;
The sliders operate via capacitive touch. You can use them to detect if someone has their finger on the circular pads at either end (which let you treat them like buttons), or you can detect the position of the finger along the slider by checking the relative values as the capacitance changes.&lt;br /&gt;
&lt;br /&gt;
The left slider is on pins 12 (bottom) and 15 (top), right slider is on pins 14 (bottom) and 27 (top).&lt;br /&gt;
&lt;br /&gt;
More info from MicroPython about [http://docs.micropython.org/en/latest/esp32/quickref.html?highlight=touchpad#capacitive-touch capacitive touch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from machine import Pin, TouchPad&lt;br /&gt;
import aiko.common&lt;br /&gt;
&lt;br /&gt;
bottom_left = TouchPad(Pin(12))&lt;br /&gt;
top_left = TouchPad(Pin(15))&lt;br /&gt;
bottom_right = TouchPad(Pin(14))&lt;br /&gt;
top_right = TouchPad(Pin(27))&lt;br /&gt;
&lt;br /&gt;
# is this button pressed?&lt;br /&gt;
# the commons library returns true/false&lt;br /&gt;
pressed_bottom_left = common.touch_pins_check([bottom_left])&lt;br /&gt;
&lt;br /&gt;
# check where we are along the slider&lt;br /&gt;
# the &#039;read&#039; functions return an integer of the &#039;strength&#039; of the &lt;br /&gt;
# capacitance. As you move your finger between the endpoints, &lt;br /&gt;
#the relative value of the difference between them will change.&lt;br /&gt;
slider_left = bottom_left.read() - bottom_left.read()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Micropython functions&lt;br /&gt;
* &#039;&#039;&#039;touchpad.read()&#039;&#039;&#039; - gives you the current value of the sensor. It will be large when not touched (over 1000) and smaller when touched.&lt;br /&gt;
Aiko functions&lt;br /&gt;
* &#039;&#039;&#039;common.touch_pins_check(touchpad_array)&#039;&#039;&#039; - Returns true if &#039;&#039;all&#039;&#039; the touchpad sensors listed are being touched, false otherwise.&lt;br /&gt;
&lt;br /&gt;
=== SAOs (simple addons) ===&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_SoftwareDev&amp;diff=1300</id>
		<title>Swagbadge2021 SoftwareDev</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_SoftwareDev&amp;diff=1300"/>
		<updated>2021-01-16T23:22:47Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* MQTT */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:Badge Software Development}}&lt;br /&gt;
&lt;br /&gt;
Want to write your own programs to run on your badge? This page gives a brief overview of the software architecture, an example of a program, and a reference guide on how to access the hardware.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;float:right&amp;quot;&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
The badge runs [https://micropython.org MicroPython] (written by [http://dpgeorge.net/ Damien George] from Melbourne!) and has the [https://github.com/geekscape/aiko_engine_mp Aiko framework] (written by OHMC&#039;s [https://twitter.com/geekscape Andy Gelme]) loaded on it.&lt;br /&gt;
&lt;br /&gt;
MicroPython gives you libraries to access the ESP32 microprocessor functionality. Things like: reading and writing to specific pins on the processor or performing operating system functions such as accessing the file system).&lt;br /&gt;
&lt;br /&gt;
Aiko gives you convenience libraries for driving the badge hardware like the OLED screens, as well as running threads to keep your badge connected to wifi, a connection to the MQTT server, the emergency-stop function to prevent runaway code, and an automatic upgrade function so we can ship upgrades to your device without you having to wrangle git.&lt;br /&gt;
&lt;br /&gt;
== Sample code ==&lt;br /&gt;
&lt;br /&gt;
This code writes &amp;quot;Hello world&amp;quot; to one screen, while displaying the status of the wifi, MQTT connection, button presses and slider status on the left hand screen.&lt;br /&gt;
&lt;br /&gt;
It demonstrates how to use the Aiko event loop to periodically poll for hardware state, as well as how to access some of the features of the badge.&lt;br /&gt;
&lt;br /&gt;
You can find more example code in the &#039;&#039;&#039;examples&#039;&#039;&#039; directory of the [https://github.com/geekscape/aiko_engine_mp/tree/master/examples Aiko repository] on github.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot; style=&amp;quot;overflow:auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;font-weight:bold;line-height:1.6;&amp;quot;&amp;gt;Example code: use &amp;quot;expand&amp;quot; to view&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;nowiki&amp;gt;&lt;br /&gt;
# examples/helloworld.py&lt;br /&gt;
#&lt;br /&gt;
# Writes a message to the oled and displays some state info&lt;br /&gt;
#&lt;br /&gt;
# Usage&lt;br /&gt;
# ~~~~~&lt;br /&gt;
# import examples.helloworld as helloworld&lt;br /&gt;
# from examples.helloworld import run&lt;br /&gt;
# run()&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
from machine import Pin, TouchPad&lt;br /&gt;
import aiko.event as event&lt;br /&gt;
import aiko.oled as oled&lt;br /&gt;
&lt;br /&gt;
title = &amp;quot;Hello!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
import configuration.main&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Buttons: underneath the screens&lt;br /&gt;
button_right = Pin(17, Pin.IN, Pin.PULL_UP)&lt;br /&gt;
button_left = Pin(16, Pin.IN, Pin.PULL_UP)&lt;br /&gt;
&lt;br /&gt;
# Clean out the whole line that was there before&lt;br /&gt;
# Write some new text and show it&lt;br /&gt;
def oled_write_line(oled_target, x, y, text):&lt;br /&gt;
    oled_target.fill_rect(0,y,oled.width, oled.font_size, oled.bg)&lt;br /&gt;
    oled_target.text(text, x, y)&lt;br /&gt;
    oled_target.show()&lt;br /&gt;
    &lt;br /&gt;
def status():&lt;br /&gt;
    sliders = touch_slider_handler()&lt;br /&gt;
    oledL = oled.oleds[0]&lt;br /&gt;
    oledR = oled.oleds[1]&lt;br /&gt;
    oled.write_line(oledR, 1, 10, &amp;quot;Hello world!&amp;quot;)&lt;br /&gt;
    oled_write_line(oledL, 1, 10, &amp;quot;Wifi: &amp;quot;+str(net.is_connected()))&lt;br /&gt;
    oled_write_line(oledL, 1, 20, &amp;quot;MQTT: &amp;quot;+str(mqtt.is_connected()))&lt;br /&gt;
    oled_write_line(oledL, 1, 30, &amp;quot; &amp;quot;+str(int(not(buttonL.value())))+&amp;quot; Button &amp;quot;+str(int(not(buttonR.value()))))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Check on the status of the badge hardware and display that every 500ms          &lt;br /&gt;
def run():&lt;br /&gt;
    oled.oleds_clear(oled.bg)&lt;br /&gt;
    oled.set_title(title)&lt;br /&gt;
    event.add_timer_handler(status, 500)&lt;br /&gt;
    try:&lt;br /&gt;
        event.loop()&lt;br /&gt;
    finally:&lt;br /&gt;
        event.remove_timer_handler(statusbar)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of a Swagbadge application ==&lt;br /&gt;
&lt;br /&gt;
An application runs when the Aiko framework is also running, so you can rely on having all the badge services available.&lt;br /&gt;
&lt;br /&gt;
An application is designed to be triggered when the badge is rebooted (either via pushing the button on the back, or via using ^D in the repl). The badge knows which application to run by the state of the &amp;lt;code&amp;gt;configuration\main.py&amp;lt;/code&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
The framework will call your application&#039;s &#039;&#039;&#039;initialise()&#039;&#039;&#039; function. The framework is running an event loop, so the initialise function is the place to add in event handlers to respond to actions you take on the badge.&lt;br /&gt;
&lt;br /&gt;
{{Note|Note: Refreshing the OLEDs is reasonably intense on the microprocessor. If you have too many event loops triggering too often and/or too much screen activity, you can starve the badge of resources. This can produce wifi dropouts, or non-responsiveness. If you have a lot of screen activity, consider using a buffer or recording state and just doing a screen update periodically}}&lt;br /&gt;
&lt;br /&gt;
== Software reference ==&lt;br /&gt;
&lt;br /&gt;
=== MicroPython environment ===&lt;br /&gt;
&lt;br /&gt;
[https://micropython.org MicroPython docs]&lt;br /&gt;
&lt;br /&gt;
==== Special files ====&lt;br /&gt;
&lt;br /&gt;
There are two special files which are run automatically by MicroPython if they exist on the filesystem: &amp;lt;code&amp;gt;boot.py&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;boot.py&#039;&#039;&#039;: This file is run first on power up/reset. We don&#039;t modify it from what MicroPython ships with, but it&#039;s important to know it exists (and not to delete it), and is interesting to look into it to see what it does.&lt;br /&gt;
* &#039;&#039;&#039;main.py&#039;&#039;&#039;: This is run after boot.py so if you want something to automatically happen on boot/reset, this is where to put it. We use this to start up the Aiko framework, initialise the hardware (such as the network and mqtt) and start up any application that is configured inside &amp;lt;code&amp;gt;configuration/main.py&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Directory structure ====&lt;br /&gt;
&lt;br /&gt;
What&#039;s on the processor? Where does it live?&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;main.py&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;boot.py&amp;lt;/code&amp;gt; - files run on bootup&lt;br /&gt;
* &amp;lt;code&amp;gt;lib&amp;lt;/code&amp;gt; - code in here is aiko framework code and automatically in the micropython &#039;path&#039;.&lt;br /&gt;
** &amp;lt;code&amp;gt;aiko&amp;lt;/code&amp;gt; - the aiko framework&lt;br /&gt;
* &amp;lt;code&amp;gt;applications&amp;lt;/code&amp;gt; - programs to run automatically on bootup. Must have an initialise function&lt;br /&gt;
* &amp;lt;code&amp;gt;configuration&amp;lt;/code&amp;gt; - control the config of aiko using files in here&lt;br /&gt;
* &amp;lt;code&amp;gt;examples&amp;lt;/code&amp;gt; - sample code!&lt;br /&gt;
&lt;br /&gt;
You can&#039;t edit the files directly on the processor (there&#039;s no editing tooling): you edit a copy of it on your computer, then use mpfshell to &amp;lt;code&amp;gt;put&amp;lt;/code&amp;gt; it onto the badge.&lt;br /&gt;
&lt;br /&gt;
For micropython purposes, you can use the &amp;lt;code&amp;gt;import&amp;lt;/code&amp;gt; statement to import anything in the &amp;lt;code&amp;gt;lib&amp;lt;/code&amp;gt; directory without prefacing it with &amp;quot;lib&amp;quot;, anything else is imported from root.&lt;br /&gt;
For example:&lt;br /&gt;
* to import lib/aiko/net.py, you would use &amp;lt;code&amp;gt;import aiko.net&amp;lt;/code&amp;gt;&lt;br /&gt;
* to import examples/showcase.py, you would use &amp;lt;code&amp;gt;import examples.showcase&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because the aiko configuration files are, themselves, just python, you can also do &amp;lt;code&amp;gt;import configuration.main.settings&amp;lt;/code&amp;gt; where the file is in /configuration/main.py but it contains a datastructure called &#039;settings&#039;.&lt;br /&gt;
&lt;br /&gt;
== Software development ==&lt;br /&gt;
&lt;br /&gt;
=== MQTT ===&lt;br /&gt;
&lt;br /&gt;
See [[Swagbadge2021_MQTT]]&lt;br /&gt;
&lt;br /&gt;
=== Aiko ===&lt;br /&gt;
The Aiko Engine is what runs after boot (FreeRTOS, then microPython). Aiko provides a framework for developing applications, by providing higher level abstractions over the basic hardware, events, messaging and other conveniences. Basically, a lot of house keeping that you&#039;d end up writing yourself. After boot, there are two background threads, one looking after Wi-Fi connectivity and the other looking after MQTT connectivity.  &lt;br /&gt;
There are also three event handlers: MQTT keep-alive, firmware upgrader and the work-in-progress SwagBadge application handler.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; aiko.event.event_list.print()&lt;br /&gt;
&amp;lt;function swagbadge_handler at 0x3ffe6c70&amp;gt; every 5000 next 23099&lt;br /&gt;
&amp;lt;function upgrade_handler at 0x3ffedfa0&amp;gt; every 5000 next 23099&lt;br /&gt;
&amp;lt;function mqtt_ping_handler at 0x3ffe9820&amp;gt; every 60000 next 73672&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That last handler, which every 5 seconds is updating the title bar &amp;quot;LCA2021&amp;quot; &amp;lt;--&amp;gt; &amp;quot;SwagBadge&amp;quot; (see https://github.com/geekscape/aiko_engine_mp/blob/master/applications/swagbadge.py ).&lt;br /&gt;
&lt;br /&gt;
You can stop a handler, like this (this will stop the top bar status updater):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; import applications.swagbadge&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; aiko.event.remove_timer_handler(application.swagbadge_handler)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Replacing the swagbadge application with your own ===&lt;br /&gt;
&lt;br /&gt;
Edit configuration/main.py and set &amp;quot;application&amp;quot;: &amp;quot;application/yourcode&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Pushing new code ===&lt;br /&gt;
Occasionally you might find that the updated source code that you just used the mpfshell &amp;quot;put&amp;quot; command to transfer isn&#039;t properly stored on the ESP32 microPython flash filesystem. After rebooting, you might see unexpected errors. A simple way to check is to use the mpfshell &amp;quot;cat&amp;quot; command to check that the file was completely transferred.  &lt;br /&gt;
&lt;br /&gt;
The safest way to update code is to perform a reboot after transferring all the files. Doing a soft-reboot using Control-D doesn&#039;t take long, i.e it is faster and easier than doing a hard-reboot with the reset button. The good thing about a reboot (microPython interpreter restart) is that there is no confusion about the complete state of your system, i.e what references have been held onto from your older source code that might still be running in a thread or as an event handler (via the Aiko Engine framework).&lt;br /&gt;
&lt;br /&gt;
You can also delete all running modules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.modules.clear() &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More details in https://spectrum.chat/lca2021-swagbadge/software/safe-software-updates~ba541e3c-d8a2-41a8-ac47-71d87696de2d&lt;br /&gt;
&lt;br /&gt;
=== Reboot to shell / Force runaway code to stop ===&lt;br /&gt;
&lt;br /&gt;
It&#039;s possible to write code that will leave your badge unresponsive. Rebooting just reruns the same bad code. What to do?&lt;br /&gt;
&lt;br /&gt;
* Place a finger on each of the bottom slider pads, either side of the microprocessor. &lt;br /&gt;
* Trigger a restart by using the button on the back of the badge, or Ctrl-D in repl (if you can get into repl)&lt;br /&gt;
&lt;br /&gt;
The badge will restart but not autorun any code, just drop you back at the repl prompt. From there you can &amp;lt;code&amp;gt;put&amp;lt;/code&amp;gt; bugfixed code back onto the device.&lt;br /&gt;
&lt;br /&gt;
See https://github.com/geekscape/aiko_engine_mp/blob/a5b5593d37509df64a3dcb4cdc3d13a411152d82/main.py#L20&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Hardware reference ==&lt;br /&gt;
&lt;br /&gt;
=== OLED screens ===&lt;br /&gt;
&lt;br /&gt;
==== via MQTT ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;(oled:clear)&#039;&#039;&#039; : clears both screens&lt;br /&gt;
* &#039;&#039;&#039;(oled:log Hello World!)&#039;&#039;&#039; : writes a message along the bottom of the screens, scrolling up whatever is there out of the way&lt;br /&gt;
* &#039;&#039;&#039;(oled:pixel x y)&#039;&#039;&#039; : lights a pixel at that spot&lt;br /&gt;
* &#039;&#039;&#039;(oled:text x y This is a test!)&#039;&#039;&#039; : Puts some text at the position x,y. It will be displayed over the top of whatever&#039;s there.&lt;br /&gt;
&lt;br /&gt;
==== via API ====&lt;br /&gt;
&lt;br /&gt;
On the badge, by default the two oleds work as a single long screen, with text split across both of them. You can access a specific oled and use the underlying functions to write to them&lt;br /&gt;
&lt;br /&gt;
Library&lt;br /&gt;
* &#039;&#039;&#039;from aiko import oled&#039;&#039;&#039; # make the oled functions available for use within your code&lt;br /&gt;
&lt;br /&gt;
Globals&lt;br /&gt;
* &#039;&#039;&#039;[] oled.oleds&#039;&#039;&#039; # an array of oleds, letting you address them separately if you choose&lt;br /&gt;
* &#039;&#039;&#039;int oled.fg/oled.bg&#039;&#039;&#039; # get/set fg and bg colours (0 or 1)&lt;br /&gt;
* &#039;&#039;&#039;int oled.font_size&#039;&#039;&#039; # helpful to work out how much space a line of text will take up&lt;br /&gt;
* &#039;&#039;&#039;boolean oled.lock_title&#039;&#039;&#039; # true/false. True means the display always shows the title. False means it&#039;ll be wiped once the display is cleared.&lt;br /&gt;
&lt;br /&gt;
Functions&lt;br /&gt;
* &#039;&#039;&#039;oled.initialise()&#039;&#039;&#039; # uses configuration.oled.settings by default, normally already invoked by the base swagbadge handler&lt;br /&gt;
* &#039;&#039;&#039;oled.oleds_clear(colour)&#039;&#039;&#039; # pass in oled.bg or oled.fg for easy set. Wipes the display&lt;br /&gt;
* &#039;&#039;&#039;oled.log(text)&#039;&#039;&#039; # scroll up text to insert a new line at the bottom of the display&lt;br /&gt;
* &#039;&#039;&#039;oled.text(text, x, y, colour)&#039;&#039;&#039; # add text at the position x,y in the colour specified. Note: does not clear the contents at this spot first.&lt;br /&gt;
* &#039;&#039;&#039;oled.oleds_show()&#039;&#039;&#039; # refresh the display with the latest text/image additions&lt;br /&gt;
* &#039;&#039;&#039;oled.set_title(text)&#039;&#039;&#039; # set the title text&lt;br /&gt;
* &#039;&#039;&#039;oled.write_title()&#039;&#039;&#039; # write the title text&lt;br /&gt;
&lt;br /&gt;
Coming soon - a way to easily write images to an oled.&lt;br /&gt;
&lt;br /&gt;
=== Screen buttons ===&lt;br /&gt;
&lt;br /&gt;
If you push (gently!) on the screens, you&#039;ll discover they double as buttons: there&#039;s a small switch under each OLED that is pressed when you push down on the screen.&lt;br /&gt;
&lt;br /&gt;
{{Note|&#039;&#039;&#039;Warning&#039;&#039;&#039;: Push on the &#039;&#039;&#039;middle&#039;&#039;&#039; of the screen, not the edge. This will minimise the risk of bending... and breaking... the screen.}}&lt;br /&gt;
&lt;br /&gt;
The left screen button is pin 16. The right screen button is pin 17.&lt;br /&gt;
&lt;br /&gt;
==== via API ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from machine import Pin&lt;br /&gt;
&lt;br /&gt;
button_left = Pin(16, Pin.IN, Pin.PULL_UP)&lt;br /&gt;
button_right = Pin(17, Pin.IN, Pin.PULL_UP)&lt;br /&gt;
&lt;br /&gt;
pressed = not(button_left.value())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The button sends &amp;quot;1&amp;quot; when it&#039;s &#039;&#039;not&#039;&#039; being pressed, and &amp;quot;0&amp;quot; when it is. This is counterintuitive to most of us, so I recommend inverting the value when reading it.&lt;br /&gt;
&lt;br /&gt;
=== Sliders ===&lt;br /&gt;
&lt;br /&gt;
The sliders operate via capacitive touch. You can use them to detect if someone has their finger on the circular pads at either end (which let you treat them like buttons), or you can detect the position of the finger along the slider by checking the relative values as the capacitance changes.&lt;br /&gt;
&lt;br /&gt;
The left slider is on pins 12 (bottom) and 15 (top), right slider is on pins 14 (bottom) and 27 (top).&lt;br /&gt;
&lt;br /&gt;
More info from MicroPython about [http://docs.micropython.org/en/latest/esp32/quickref.html?highlight=touchpad#capacitive-touch capacitive touch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from machine import Pin, TouchPad&lt;br /&gt;
import aiko.common&lt;br /&gt;
&lt;br /&gt;
bottom_left = TouchPad(Pin(12))&lt;br /&gt;
top_left = TouchPad(Pin(15))&lt;br /&gt;
bottom_right = TouchPad(Pin(14))&lt;br /&gt;
top_right = TouchPad(Pin(27))&lt;br /&gt;
&lt;br /&gt;
# is this button pressed?&lt;br /&gt;
# the commons library returns true/false&lt;br /&gt;
pressed_bottom_left = common.touch_pins_check([bottom_left])&lt;br /&gt;
&lt;br /&gt;
# check where we are along the slider&lt;br /&gt;
# the &#039;read&#039; functions return an integer of the &#039;strength&#039; of the &lt;br /&gt;
# capacitance. As you move your finger between the endpoints, &lt;br /&gt;
#the relative value of the difference between them will change.&lt;br /&gt;
slider_left = bottom_left.read() - bottom_left.read()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Micropython functions&lt;br /&gt;
* &#039;&#039;&#039;touchpad.read()&#039;&#039;&#039; - gives you the current value of the sensor. It will be large when not touched (over 1000) and smaller when touched.&lt;br /&gt;
Aiko functions&lt;br /&gt;
* &#039;&#039;&#039;common.touch_pins_check(touchpad_array)&#039;&#039;&#039; - Returns true if &#039;&#039;all&#039;&#039; the touchpad sensors listed are being touched, false otherwise.&lt;br /&gt;
&lt;br /&gt;
=== SAOs (simple addons) ===&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_SoftwareDev&amp;diff=1299</id>
		<title>Swagbadge2021 SoftwareDev</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_SoftwareDev&amp;diff=1299"/>
		<updated>2021-01-16T23:22:17Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:Badge Software Development}}&lt;br /&gt;
&lt;br /&gt;
Want to write your own programs to run on your badge? This page gives a brief overview of the software architecture, an example of a program, and a reference guide on how to access the hardware.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;float:right&amp;quot;&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
The badge runs [https://micropython.org MicroPython] (written by [http://dpgeorge.net/ Damien George] from Melbourne!) and has the [https://github.com/geekscape/aiko_engine_mp Aiko framework] (written by OHMC&#039;s [https://twitter.com/geekscape Andy Gelme]) loaded on it.&lt;br /&gt;
&lt;br /&gt;
MicroPython gives you libraries to access the ESP32 microprocessor functionality. Things like: reading and writing to specific pins on the processor or performing operating system functions such as accessing the file system).&lt;br /&gt;
&lt;br /&gt;
Aiko gives you convenience libraries for driving the badge hardware like the OLED screens, as well as running threads to keep your badge connected to wifi, a connection to the MQTT server, the emergency-stop function to prevent runaway code, and an automatic upgrade function so we can ship upgrades to your device without you having to wrangle git.&lt;br /&gt;
&lt;br /&gt;
== Sample code ==&lt;br /&gt;
&lt;br /&gt;
This code writes &amp;quot;Hello world&amp;quot; to one screen, while displaying the status of the wifi, MQTT connection, button presses and slider status on the left hand screen.&lt;br /&gt;
&lt;br /&gt;
It demonstrates how to use the Aiko event loop to periodically poll for hardware state, as well as how to access some of the features of the badge.&lt;br /&gt;
&lt;br /&gt;
You can find more example code in the &#039;&#039;&#039;examples&#039;&#039;&#039; directory of the [https://github.com/geekscape/aiko_engine_mp/tree/master/examples Aiko repository] on github.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot; style=&amp;quot;overflow:auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;font-weight:bold;line-height:1.6;&amp;quot;&amp;gt;Example code: use &amp;quot;expand&amp;quot; to view&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;nowiki&amp;gt;&lt;br /&gt;
# examples/helloworld.py&lt;br /&gt;
#&lt;br /&gt;
# Writes a message to the oled and displays some state info&lt;br /&gt;
#&lt;br /&gt;
# Usage&lt;br /&gt;
# ~~~~~&lt;br /&gt;
# import examples.helloworld as helloworld&lt;br /&gt;
# from examples.helloworld import run&lt;br /&gt;
# run()&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
from machine import Pin, TouchPad&lt;br /&gt;
import aiko.event as event&lt;br /&gt;
import aiko.oled as oled&lt;br /&gt;
&lt;br /&gt;
title = &amp;quot;Hello!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
import configuration.main&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Buttons: underneath the screens&lt;br /&gt;
button_right = Pin(17, Pin.IN, Pin.PULL_UP)&lt;br /&gt;
button_left = Pin(16, Pin.IN, Pin.PULL_UP)&lt;br /&gt;
&lt;br /&gt;
# Clean out the whole line that was there before&lt;br /&gt;
# Write some new text and show it&lt;br /&gt;
def oled_write_line(oled_target, x, y, text):&lt;br /&gt;
    oled_target.fill_rect(0,y,oled.width, oled.font_size, oled.bg)&lt;br /&gt;
    oled_target.text(text, x, y)&lt;br /&gt;
    oled_target.show()&lt;br /&gt;
    &lt;br /&gt;
def status():&lt;br /&gt;
    sliders = touch_slider_handler()&lt;br /&gt;
    oledL = oled.oleds[0]&lt;br /&gt;
    oledR = oled.oleds[1]&lt;br /&gt;
    oled.write_line(oledR, 1, 10, &amp;quot;Hello world!&amp;quot;)&lt;br /&gt;
    oled_write_line(oledL, 1, 10, &amp;quot;Wifi: &amp;quot;+str(net.is_connected()))&lt;br /&gt;
    oled_write_line(oledL, 1, 20, &amp;quot;MQTT: &amp;quot;+str(mqtt.is_connected()))&lt;br /&gt;
    oled_write_line(oledL, 1, 30, &amp;quot; &amp;quot;+str(int(not(buttonL.value())))+&amp;quot; Button &amp;quot;+str(int(not(buttonR.value()))))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Check on the status of the badge hardware and display that every 500ms          &lt;br /&gt;
def run():&lt;br /&gt;
    oled.oleds_clear(oled.bg)&lt;br /&gt;
    oled.set_title(title)&lt;br /&gt;
    event.add_timer_handler(status, 500)&lt;br /&gt;
    try:&lt;br /&gt;
        event.loop()&lt;br /&gt;
    finally:&lt;br /&gt;
        event.remove_timer_handler(statusbar)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of a Swagbadge application ==&lt;br /&gt;
&lt;br /&gt;
An application runs when the Aiko framework is also running, so you can rely on having all the badge services available.&lt;br /&gt;
&lt;br /&gt;
An application is designed to be triggered when the badge is rebooted (either via pushing the button on the back, or via using ^D in the repl). The badge knows which application to run by the state of the &amp;lt;code&amp;gt;configuration\main.py&amp;lt;/code&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
The framework will call your application&#039;s &#039;&#039;&#039;initialise()&#039;&#039;&#039; function. The framework is running an event loop, so the initialise function is the place to add in event handlers to respond to actions you take on the badge.&lt;br /&gt;
&lt;br /&gt;
{{Note|Note: Refreshing the OLEDs is reasonably intense on the microprocessor. If you have too many event loops triggering too often and/or too much screen activity, you can starve the badge of resources. This can produce wifi dropouts, or non-responsiveness. If you have a lot of screen activity, consider using a buffer or recording state and just doing a screen update periodically}}&lt;br /&gt;
&lt;br /&gt;
== Software reference ==&lt;br /&gt;
&lt;br /&gt;
=== MicroPython environment ===&lt;br /&gt;
&lt;br /&gt;
[https://micropython.org MicroPython docs]&lt;br /&gt;
&lt;br /&gt;
==== Special files ====&lt;br /&gt;
&lt;br /&gt;
There are two special files which are run automatically by MicroPython if they exist on the filesystem: &amp;lt;code&amp;gt;boot.py&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;boot.py&#039;&#039;&#039;: This file is run first on power up/reset. We don&#039;t modify it from what MicroPython ships with, but it&#039;s important to know it exists (and not to delete it), and is interesting to look into it to see what it does.&lt;br /&gt;
* &#039;&#039;&#039;main.py&#039;&#039;&#039;: This is run after boot.py so if you want something to automatically happen on boot/reset, this is where to put it. We use this to start up the Aiko framework, initialise the hardware (such as the network and mqtt) and start up any application that is configured inside &amp;lt;code&amp;gt;configuration/main.py&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Directory structure ====&lt;br /&gt;
&lt;br /&gt;
What&#039;s on the processor? Where does it live?&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;main.py&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;boot.py&amp;lt;/code&amp;gt; - files run on bootup&lt;br /&gt;
* &amp;lt;code&amp;gt;lib&amp;lt;/code&amp;gt; - code in here is aiko framework code and automatically in the micropython &#039;path&#039;.&lt;br /&gt;
** &amp;lt;code&amp;gt;aiko&amp;lt;/code&amp;gt; - the aiko framework&lt;br /&gt;
* &amp;lt;code&amp;gt;applications&amp;lt;/code&amp;gt; - programs to run automatically on bootup. Must have an initialise function&lt;br /&gt;
* &amp;lt;code&amp;gt;configuration&amp;lt;/code&amp;gt; - control the config of aiko using files in here&lt;br /&gt;
* &amp;lt;code&amp;gt;examples&amp;lt;/code&amp;gt; - sample code!&lt;br /&gt;
&lt;br /&gt;
You can&#039;t edit the files directly on the processor (there&#039;s no editing tooling): you edit a copy of it on your computer, then use mpfshell to &amp;lt;code&amp;gt;put&amp;lt;/code&amp;gt; it onto the badge.&lt;br /&gt;
&lt;br /&gt;
For micropython purposes, you can use the &amp;lt;code&amp;gt;import&amp;lt;/code&amp;gt; statement to import anything in the &amp;lt;code&amp;gt;lib&amp;lt;/code&amp;gt; directory without prefacing it with &amp;quot;lib&amp;quot;, anything else is imported from root.&lt;br /&gt;
For example:&lt;br /&gt;
* to import lib/aiko/net.py, you would use &amp;lt;code&amp;gt;import aiko.net&amp;lt;/code&amp;gt;&lt;br /&gt;
* to import examples/showcase.py, you would use &amp;lt;code&amp;gt;import examples.showcase&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because the aiko configuration files are, themselves, just python, you can also do &amp;lt;code&amp;gt;import configuration.main.settings&amp;lt;/code&amp;gt; where the file is in /configuration/main.py but it contains a datastructure called &#039;settings&#039;.&lt;br /&gt;
&lt;br /&gt;
== Software development ==&lt;br /&gt;
&lt;br /&gt;
=== MQTT ===&lt;br /&gt;
&lt;br /&gt;
See [[Link Swagbadge2021_MQTT]]&lt;br /&gt;
&lt;br /&gt;
=== Aiko ===&lt;br /&gt;
The Aiko Engine is what runs after boot (FreeRTOS, then microPython). Aiko provides a framework for developing applications, by providing higher level abstractions over the basic hardware, events, messaging and other conveniences. Basically, a lot of house keeping that you&#039;d end up writing yourself. After boot, there are two background threads, one looking after Wi-Fi connectivity and the other looking after MQTT connectivity.  &lt;br /&gt;
There are also three event handlers: MQTT keep-alive, firmware upgrader and the work-in-progress SwagBadge application handler.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; aiko.event.event_list.print()&lt;br /&gt;
&amp;lt;function swagbadge_handler at 0x3ffe6c70&amp;gt; every 5000 next 23099&lt;br /&gt;
&amp;lt;function upgrade_handler at 0x3ffedfa0&amp;gt; every 5000 next 23099&lt;br /&gt;
&amp;lt;function mqtt_ping_handler at 0x3ffe9820&amp;gt; every 60000 next 73672&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That last handler, which every 5 seconds is updating the title bar &amp;quot;LCA2021&amp;quot; &amp;lt;--&amp;gt; &amp;quot;SwagBadge&amp;quot; (see https://github.com/geekscape/aiko_engine_mp/blob/master/applications/swagbadge.py ).&lt;br /&gt;
&lt;br /&gt;
You can stop a handler, like this (this will stop the top bar status updater):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; import applications.swagbadge&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; aiko.event.remove_timer_handler(application.swagbadge_handler)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Replacing the swagbadge application with your own ===&lt;br /&gt;
&lt;br /&gt;
Edit configuration/main.py and set &amp;quot;application&amp;quot;: &amp;quot;application/yourcode&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Pushing new code ===&lt;br /&gt;
Occasionally you might find that the updated source code that you just used the mpfshell &amp;quot;put&amp;quot; command to transfer isn&#039;t properly stored on the ESP32 microPython flash filesystem. After rebooting, you might see unexpected errors. A simple way to check is to use the mpfshell &amp;quot;cat&amp;quot; command to check that the file was completely transferred.  &lt;br /&gt;
&lt;br /&gt;
The safest way to update code is to perform a reboot after transferring all the files. Doing a soft-reboot using Control-D doesn&#039;t take long, i.e it is faster and easier than doing a hard-reboot with the reset button. The good thing about a reboot (microPython interpreter restart) is that there is no confusion about the complete state of your system, i.e what references have been held onto from your older source code that might still be running in a thread or as an event handler (via the Aiko Engine framework).&lt;br /&gt;
&lt;br /&gt;
You can also delete all running modules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.modules.clear() &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More details in https://spectrum.chat/lca2021-swagbadge/software/safe-software-updates~ba541e3c-d8a2-41a8-ac47-71d87696de2d&lt;br /&gt;
&lt;br /&gt;
=== Reboot to shell / Force runaway code to stop ===&lt;br /&gt;
&lt;br /&gt;
It&#039;s possible to write code that will leave your badge unresponsive. Rebooting just reruns the same bad code. What to do?&lt;br /&gt;
&lt;br /&gt;
* Place a finger on each of the bottom slider pads, either side of the microprocessor. &lt;br /&gt;
* Trigger a restart by using the button on the back of the badge, or Ctrl-D in repl (if you can get into repl)&lt;br /&gt;
&lt;br /&gt;
The badge will restart but not autorun any code, just drop you back at the repl prompt. From there you can &amp;lt;code&amp;gt;put&amp;lt;/code&amp;gt; bugfixed code back onto the device.&lt;br /&gt;
&lt;br /&gt;
See https://github.com/geekscape/aiko_engine_mp/blob/a5b5593d37509df64a3dcb4cdc3d13a411152d82/main.py#L20&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Hardware reference ==&lt;br /&gt;
&lt;br /&gt;
=== OLED screens ===&lt;br /&gt;
&lt;br /&gt;
==== via MQTT ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;(oled:clear)&#039;&#039;&#039; : clears both screens&lt;br /&gt;
* &#039;&#039;&#039;(oled:log Hello World!)&#039;&#039;&#039; : writes a message along the bottom of the screens, scrolling up whatever is there out of the way&lt;br /&gt;
* &#039;&#039;&#039;(oled:pixel x y)&#039;&#039;&#039; : lights a pixel at that spot&lt;br /&gt;
* &#039;&#039;&#039;(oled:text x y This is a test!)&#039;&#039;&#039; : Puts some text at the position x,y. It will be displayed over the top of whatever&#039;s there.&lt;br /&gt;
&lt;br /&gt;
==== via API ====&lt;br /&gt;
&lt;br /&gt;
On the badge, by default the two oleds work as a single long screen, with text split across both of them. You can access a specific oled and use the underlying functions to write to them&lt;br /&gt;
&lt;br /&gt;
Library&lt;br /&gt;
* &#039;&#039;&#039;from aiko import oled&#039;&#039;&#039; # make the oled functions available for use within your code&lt;br /&gt;
&lt;br /&gt;
Globals&lt;br /&gt;
* &#039;&#039;&#039;[] oled.oleds&#039;&#039;&#039; # an array of oleds, letting you address them separately if you choose&lt;br /&gt;
* &#039;&#039;&#039;int oled.fg/oled.bg&#039;&#039;&#039; # get/set fg and bg colours (0 or 1)&lt;br /&gt;
* &#039;&#039;&#039;int oled.font_size&#039;&#039;&#039; # helpful to work out how much space a line of text will take up&lt;br /&gt;
* &#039;&#039;&#039;boolean oled.lock_title&#039;&#039;&#039; # true/false. True means the display always shows the title. False means it&#039;ll be wiped once the display is cleared.&lt;br /&gt;
&lt;br /&gt;
Functions&lt;br /&gt;
* &#039;&#039;&#039;oled.initialise()&#039;&#039;&#039; # uses configuration.oled.settings by default, normally already invoked by the base swagbadge handler&lt;br /&gt;
* &#039;&#039;&#039;oled.oleds_clear(colour)&#039;&#039;&#039; # pass in oled.bg or oled.fg for easy set. Wipes the display&lt;br /&gt;
* &#039;&#039;&#039;oled.log(text)&#039;&#039;&#039; # scroll up text to insert a new line at the bottom of the display&lt;br /&gt;
* &#039;&#039;&#039;oled.text(text, x, y, colour)&#039;&#039;&#039; # add text at the position x,y in the colour specified. Note: does not clear the contents at this spot first.&lt;br /&gt;
* &#039;&#039;&#039;oled.oleds_show()&#039;&#039;&#039; # refresh the display with the latest text/image additions&lt;br /&gt;
* &#039;&#039;&#039;oled.set_title(text)&#039;&#039;&#039; # set the title text&lt;br /&gt;
* &#039;&#039;&#039;oled.write_title()&#039;&#039;&#039; # write the title text&lt;br /&gt;
&lt;br /&gt;
Coming soon - a way to easily write images to an oled.&lt;br /&gt;
&lt;br /&gt;
=== Screen buttons ===&lt;br /&gt;
&lt;br /&gt;
If you push (gently!) on the screens, you&#039;ll discover they double as buttons: there&#039;s a small switch under each OLED that is pressed when you push down on the screen.&lt;br /&gt;
&lt;br /&gt;
{{Note|&#039;&#039;&#039;Warning&#039;&#039;&#039;: Push on the &#039;&#039;&#039;middle&#039;&#039;&#039; of the screen, not the edge. This will minimise the risk of bending... and breaking... the screen.}}&lt;br /&gt;
&lt;br /&gt;
The left screen button is pin 16. The right screen button is pin 17.&lt;br /&gt;
&lt;br /&gt;
==== via API ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from machine import Pin&lt;br /&gt;
&lt;br /&gt;
button_left = Pin(16, Pin.IN, Pin.PULL_UP)&lt;br /&gt;
button_right = Pin(17, Pin.IN, Pin.PULL_UP)&lt;br /&gt;
&lt;br /&gt;
pressed = not(button_left.value())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The button sends &amp;quot;1&amp;quot; when it&#039;s &#039;&#039;not&#039;&#039; being pressed, and &amp;quot;0&amp;quot; when it is. This is counterintuitive to most of us, so I recommend inverting the value when reading it.&lt;br /&gt;
&lt;br /&gt;
=== Sliders ===&lt;br /&gt;
&lt;br /&gt;
The sliders operate via capacitive touch. You can use them to detect if someone has their finger on the circular pads at either end (which let you treat them like buttons), or you can detect the position of the finger along the slider by checking the relative values as the capacitance changes.&lt;br /&gt;
&lt;br /&gt;
The left slider is on pins 12 (bottom) and 15 (top), right slider is on pins 14 (bottom) and 27 (top).&lt;br /&gt;
&lt;br /&gt;
More info from MicroPython about [http://docs.micropython.org/en/latest/esp32/quickref.html?highlight=touchpad#capacitive-touch capacitive touch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from machine import Pin, TouchPad&lt;br /&gt;
import aiko.common&lt;br /&gt;
&lt;br /&gt;
bottom_left = TouchPad(Pin(12))&lt;br /&gt;
top_left = TouchPad(Pin(15))&lt;br /&gt;
bottom_right = TouchPad(Pin(14))&lt;br /&gt;
top_right = TouchPad(Pin(27))&lt;br /&gt;
&lt;br /&gt;
# is this button pressed?&lt;br /&gt;
# the commons library returns true/false&lt;br /&gt;
pressed_bottom_left = common.touch_pins_check([bottom_left])&lt;br /&gt;
&lt;br /&gt;
# check where we are along the slider&lt;br /&gt;
# the &#039;read&#039; functions return an integer of the &#039;strength&#039; of the &lt;br /&gt;
# capacitance. As you move your finger between the endpoints, &lt;br /&gt;
#the relative value of the difference between them will change.&lt;br /&gt;
slider_left = bottom_left.read() - bottom_left.read()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Micropython functions&lt;br /&gt;
* &#039;&#039;&#039;touchpad.read()&#039;&#039;&#039; - gives you the current value of the sensor. It will be large when not touched (over 1000) and smaller when touched.&lt;br /&gt;
Aiko functions&lt;br /&gt;
* &#039;&#039;&#039;common.touch_pins_check(touchpad_array)&#039;&#039;&#039; - Returns true if &#039;&#039;all&#039;&#039; the touchpad sensors listed are being touched, false otherwise.&lt;br /&gt;
&lt;br /&gt;
=== SAOs (simple addons) ===&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_UpdatingSoftware&amp;diff=1298</id>
		<title>Swagbadge2021 UpdatingSoftware</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_UpdatingSoftware&amp;diff=1298"/>
		<updated>2021-01-16T23:21:05Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Software development */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Updating the software framework =&lt;br /&gt;
&lt;br /&gt;
Swagbadge owners might want to update the software framework (Aiko). Dagbadge owners will need to put the framework onto their badge before they can use it.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s how to do that!&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
* #swagbadge or #dagbadge or any ESP32 with an OLED screen&lt;br /&gt;
* Micro-USB cable&lt;br /&gt;
* Linux, Mac OS or Linux system running Python 3&lt;br /&gt;
* Command line tools: git&lt;br /&gt;
&lt;br /&gt;
== Setting up your Windows 10 system for connecting to badge hardware ==&lt;br /&gt;
&lt;br /&gt;
How to find your serial COM port on Windows: &lt;br /&gt;
* Use the Device Manager. &lt;br /&gt;
* Under the &amp;quot;Ports&amp;quot; category, you&#039;ll see one or more entries. Hopefully one of which is your badge! It will tell you what Port it is on. &lt;br /&gt;
* If you can&#039;t see your badge, you might need to go up to the View menu and use &amp;quot;Show hidden devices&amp;quot; and see if that helps.&lt;br /&gt;
&lt;br /&gt;
Windows 10 may automatically discover your #swagbadge USB hardware and automatically install the correct USB serial hardware driver, or if nothing still shows up, you might need to update your USB drivers for supporting the USB hardware CP210x on your #swagbadge, please follow these instructions:&lt;br /&gt;
* Download the CP210x drivers from [https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers Silicon Labs Windows Universal Driver]&lt;br /&gt;
* Unpack the zip file&lt;br /&gt;
* Follow the Silicon Labs instructions for [https://www.silabs.com/documents/public/application-notes/AN335.pdf INF only install] (Section 5 on page 9)&lt;br /&gt;
&lt;br /&gt;
By this point, you have know the serial COM port that your #swagbadge is connected to, e.g COM4&lt;br /&gt;
&lt;br /&gt;
== Setting up your Mac OS system for connecting to #swagbadge hardware ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How to find your serial COM port on OS X: &lt;br /&gt;
&lt;br /&gt;
    $ ls /dev/tty.usb*&lt;br /&gt;
&lt;br /&gt;
Unless you have lot of dev boards (or maybe a phone) plugged in you should just see a single filename there.&lt;br /&gt;
Use this (without the `/dev/` prefix) when using the `open` command in `mpfshell`&lt;br /&gt;
&lt;br /&gt;
To get a working `mpfshell` install a recent version of Python (Python3.8 is known to work) using a installed DMG.&lt;br /&gt;
Then create a *venv* and install the necessary tools using pip.&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
    $ mkdir swag&lt;br /&gt;
    $ cd swag&lt;br /&gt;
    $ python3.8 -m venv env&lt;br /&gt;
    $ ./env/bin/pip install esptool mpfshell&lt;br /&gt;
&lt;br /&gt;
You can then run `mpfshell` to connect:&lt;br /&gt;
&lt;br /&gt;
    $ ./env/bin/mpfshell&lt;br /&gt;
    mpfs [/]&amp;gt; open &amp;lt;your device node as found previously&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setting up your Linux system for connecting to #swagbadge hardware ==&lt;br /&gt;
[Link other instructions here]&lt;br /&gt;
&lt;br /&gt;
== Setting up your Windows 10 system for installing #swagbadge firmware == &lt;br /&gt;
&lt;br /&gt;
* Install [https://docs.conda.io/en/latest/miniconda.html Miniconda3] to create a specific Python development environment. (Note we are using Python3 not Python2)&lt;br /&gt;
* Create specific Python 3 environment for playing around with your #swagbadge&lt;br /&gt;
** Start an Anaconda Powershell Prompt (aka Windows Terminal)&lt;br /&gt;
** &amp;lt;code&amp;gt;conda create --yes -n swagbadge python=3&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;conda activate swagbadge&amp;lt;/code&amp;gt;&lt;br /&gt;
* Your command prompt should now look like: &amp;lt;code&amp;gt;(swagbadge) C:\Users\[Username]&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Install some python tools to let us prepare and communicate with the badge&lt;br /&gt;
** &amp;lt;code&amp;gt;pip install esptool mpfshell&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To test that the required tools are installed, trying running the following commands&lt;br /&gt;
** &amp;lt;code&amp;gt;esptool&amp;lt;/code&amp;gt;  # Should show you help on running the esptool&lt;br /&gt;
** &amp;lt;code&amp;gt;mpfshell&amp;lt;/code&amp;gt;  # Should show three lines of output&lt;br /&gt;
*** &amp;lt;code&amp;gt;exit&amp;lt;/code&amp;gt;  #  To exit mpfshell&lt;br /&gt;
&lt;br /&gt;
== Download #swagbadge (Aiko Engine) firmware ==&lt;br /&gt;
&lt;br /&gt;
Within your Anaconda Prompt session, change directory to where you’d like the #swagbadge software to be downloaded, for example:&lt;br /&gt;
* &amp;lt;code&amp;gt;cd $HOME/software&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Download #swagbadge firmware:&lt;br /&gt;
* &amp;lt;code&amp;gt;git clone https://github.com/geekscape/aiko_engine_mp.git&amp;lt;/code&amp;gt; # NOTE: this URL will change once we&#039;re live&lt;br /&gt;
* &amp;lt;code&amp;gt;cd aiko_engine_mp&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Install MicroPython&lt;br /&gt;
* Create a directory to hold the MicroPython firmware, such as aiko_engine_mp/firmware/&lt;br /&gt;
* &amp;lt;code&amp;gt;mkdir firmware&amp;lt;/code&amp;gt;&lt;br /&gt;
* Using your web browser, download: [http://micropython.org/resources/firmware/esp32-idf4-20200902-v1.13.bin esp32-idf4-20200902-v1.13.bin] (mouse right button click → [Save As …]  saving the MicroPython firmware in the firmware directory you just made.&lt;br /&gt;
** The [http://micropython.org/download/ MicroPython download list] has a link to a bunch of firmware drivers, we are using the one for the esp32 device, with the latest 1.4 generic&lt;br /&gt;
&lt;br /&gt;
Erase #swagbadge LoLin-Lite ESP32 flash memory&lt;br /&gt;
* &amp;lt;code&amp;gt;esptool --chip esp32 --port COM3 erase_flash&amp;lt;/code&amp;gt; # adjust the port to suit.&lt;br /&gt;
* You’ll know it’s worked, if the output finishes with “Hard resetting via RTS pin…”&lt;br /&gt;
&lt;br /&gt;
Install microPython on the badge&lt;br /&gt;
* &amp;lt;code&amp;gt;esptool --chip esp32 --port COM3 --baud 460800 write_flash -z 0x1000 firmware\esp32-idf4-20200902-v1.13.bin&amp;lt;/code&amp;gt; #adjust port and firmware location if necessary&lt;br /&gt;
* You’ll know it’s worked, if the output finishes with “Hard resetting via RTS pin…”&lt;br /&gt;
&lt;br /&gt;
Test that the software is installed correctly by using mpfshell&lt;br /&gt;
* &amp;lt;code&amp;gt;mpfshell -o COM3&amp;lt;/code&amp;gt; # Adjust port to suit&lt;br /&gt;
* If it has made a connection to your badge, you will see it say&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;Connected to esp32&lt;br /&gt;
** Micropython File Shell v0.9.1, sw@kaltpost.de **&lt;br /&gt;
-- Running on Python 3.8 using PySerial 3.4 --&lt;br /&gt;
mpfs [/]&amp;gt; &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using mpfshell ==&lt;br /&gt;
&lt;br /&gt;
mpfshell has two functions: it lets you put files on/off the device, and it can give you a python shell to execute code on the device.&lt;br /&gt;
* Getting files on/off the device is a bit like commandline ftp&lt;br /&gt;
** ls - looks at the files on your micropython device&lt;br /&gt;
** lls - looks at the files on your local computer in the current directory&lt;br /&gt;
** put - puts a file to the device&lt;br /&gt;
** cat - shows you the contents of the file&lt;br /&gt;
** help() - gives you more information on the commands&lt;br /&gt;
** repl - opens up the python shell on the badge&lt;br /&gt;
&lt;br /&gt;
Note: To get out of repl, use Ctrl-Q (on Windows) which drops you back into mpfshell&lt;br /&gt;
&lt;br /&gt;
A little program to say hello world!&lt;br /&gt;
* &amp;lt;code&amp;gt; &amp;gt;&amp;gt;&amp;gt; print(&amp;quot;hello world&amp;quot;)&amp;lt;/code&amp;gt;&lt;br /&gt;
* Output: &amp;lt;code&amp;gt;hello world&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A little program to turn the blue light on the board on and off (this is on the underside of the Swagbadge, visible through a circular cutout)&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&amp;gt;&amp;gt;&amp;gt; import machine&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; pin22=machine.Pin(22, machine.Pin.OUT, machine.Pin.PULL_UP)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; pin22.value(0) &lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; pin22.value(1)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Saving your private key ==&lt;br /&gt;
&lt;br /&gt;
Use mpfshell to get the file: `configuration/keys.db`.&lt;br /&gt;
&lt;br /&gt;
== Putting the Aiko framework onto the device, using mpfshell == &lt;br /&gt;
* &amp;lt;code&amp;gt;mpfshell COM5 -s scripts\aiko.mpf&amp;lt;/code&amp;gt; #run from within the aiko_framework_mp directory&lt;br /&gt;
&lt;br /&gt;
=== Windows only: Patch mpfshell ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note!&#039;&#039; mpfshell needs a patch applied to let it run a script under Windows.&lt;br /&gt;
&lt;br /&gt;
* Inside &amp;lt;code&amp;gt;C:/users/USERNAME/Miniconda2/envs/swagbadge/Lib/site-packages/mp&amp;lt;/code&amp;gt;&lt;br /&gt;
* edit &amp;lt;code&amp;gt;mpfshell.py&amp;lt;/code&amp;gt;&lt;br /&gt;
* Search for &amp;lt;code&amp;gt;elif args.script is not None:&amp;lt;/code&amp;gt;, around line 796&lt;br /&gt;
* between that line and the next, insert two lines. It should look like:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
    elif args.script is not None:&lt;br /&gt;
&lt;br /&gt;
        if platform.system() == &amp;quot;Windows&amp;quot;:  #INSERT THIS LINE&lt;br /&gt;
            mpfs.use_rawinput = True        #INSERT THIS LINE&lt;br /&gt;
&lt;br /&gt;
        f = open(args.script, &amp;quot;r&amp;quot;)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* Python is very particular about spacing. The rest of the code uses 4 spaces for indents so follow suit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Software development =&lt;br /&gt;
&lt;br /&gt;
See [[Swagbadge2021_SoftwareDev]]&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_SoftwareDev&amp;diff=1297</id>
		<title>Swagbadge2021 SoftwareDev</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_SoftwareDev&amp;diff=1297"/>
		<updated>2021-01-16T23:20:10Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:Badge Software Development}}&lt;br /&gt;
&lt;br /&gt;
Want to write your own programs to run on your badge? This page gives a brief overview of the software architecture, an example of a program, and a reference guide on how to access the hardware.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;float:right&amp;quot;&amp;gt;&lt;br /&gt;
__TOC__ &lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
The badge runs [https://micropython.org MicroPython] (written by [http://dpgeorge.net/ Damien George] from Melbourne!) and has the [https://github.com/geekscape/aiko_engine_mp Aiko framework] (written by OHMC&#039;s [https://twitter.com/geekscape Andy Gelme]) loaded on it.&lt;br /&gt;
&lt;br /&gt;
MicroPython gives you libraries to access the ESP32 microprocessor functionality. Things like: reading and writing to specific pins on the processor or performing operating system functions such as accessing the file system).&lt;br /&gt;
&lt;br /&gt;
Aiko gives you convenience libraries for driving the badge hardware like the OLED screens, as well as running threads to keep your badge connected to wifi, a connection to the MQTT server, the emergency-stop function to prevent runaway code, and an automatic upgrade function so we can ship upgrades to your device without you having to wrangle git.&lt;br /&gt;
&lt;br /&gt;
== Sample code ==&lt;br /&gt;
&lt;br /&gt;
This code writes &amp;quot;Hello world&amp;quot; to one screen, while displaying the status of the wifi, MQTT connection, button presses and slider status on the left hand screen.&lt;br /&gt;
&lt;br /&gt;
It demonstrates how to use the Aiko event loop to periodically poll for hardware state, as well as how to access some of the features of the badge.&lt;br /&gt;
&lt;br /&gt;
You can find more example code in the &#039;&#039;&#039;examples&#039;&#039;&#039; directory of the [https://github.com/geekscape/aiko_engine_mp/tree/master/examples Aiko repository] on github.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot; style=&amp;quot;overflow:auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;font-weight:bold;line-height:1.6;&amp;quot;&amp;gt;Example code: use &amp;quot;expand&amp;quot; to view&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;nowiki&amp;gt;&lt;br /&gt;
# examples/helloworld.py&lt;br /&gt;
#&lt;br /&gt;
# Writes a message to the oled and displays some state info&lt;br /&gt;
#&lt;br /&gt;
# Usage&lt;br /&gt;
# ~~~~~&lt;br /&gt;
# import examples.helloworld as helloworld&lt;br /&gt;
# from examples.helloworld import run&lt;br /&gt;
# run()&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
from machine import Pin, TouchPad&lt;br /&gt;
import aiko.event as event&lt;br /&gt;
import aiko.oled as oled&lt;br /&gt;
&lt;br /&gt;
title = &amp;quot;Hello!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
import configuration.main&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Buttons: underneath the screens&lt;br /&gt;
button_right = Pin(17, Pin.IN, Pin.PULL_UP)&lt;br /&gt;
button_left = Pin(16, Pin.IN, Pin.PULL_UP)&lt;br /&gt;
&lt;br /&gt;
# Clean out the whole line that was there before&lt;br /&gt;
# Write some new text and show it&lt;br /&gt;
def oled_write_line(oled_target, x, y, text):&lt;br /&gt;
    oled_target.fill_rect(0,y,oled.width, oled.font_size, oled.bg)&lt;br /&gt;
    oled_target.text(text, x, y)&lt;br /&gt;
    oled_target.show()&lt;br /&gt;
    &lt;br /&gt;
def status():&lt;br /&gt;
    sliders = touch_slider_handler()&lt;br /&gt;
    oledL = oled.oleds[0]&lt;br /&gt;
    oledR = oled.oleds[1]&lt;br /&gt;
    oled.write_line(oledR, 1, 10, &amp;quot;Hello world!&amp;quot;)&lt;br /&gt;
    oled_write_line(oledL, 1, 10, &amp;quot;Wifi: &amp;quot;+str(net.is_connected()))&lt;br /&gt;
    oled_write_line(oledL, 1, 20, &amp;quot;MQTT: &amp;quot;+str(mqtt.is_connected()))&lt;br /&gt;
    oled_write_line(oledL, 1, 30, &amp;quot; &amp;quot;+str(int(not(buttonL.value())))+&amp;quot; Button &amp;quot;+str(int(not(buttonR.value()))))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Check on the status of the badge hardware and display that every 500ms          &lt;br /&gt;
def run():&lt;br /&gt;
    oled.oleds_clear(oled.bg)&lt;br /&gt;
    oled.set_title(title)&lt;br /&gt;
    event.add_timer_handler(status, 500)&lt;br /&gt;
    try:&lt;br /&gt;
        event.loop()&lt;br /&gt;
    finally:&lt;br /&gt;
        event.remove_timer_handler(statusbar)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of a Swagbadge application ==&lt;br /&gt;
&lt;br /&gt;
An application runs when the Aiko framework is also running, so you can rely on having all the badge services available.&lt;br /&gt;
&lt;br /&gt;
An application is designed to be triggered when the badge is rebooted (either via pushing the button on the back, or via using ^D in the repl). The badge knows which application to run by the state of the &amp;lt;code&amp;gt;configuration\main.py&amp;lt;/code&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
The framework will call your application&#039;s &#039;&#039;&#039;initialise()&#039;&#039;&#039; function. The framework is running an event loop, so the initialise function is the place to add in event handlers to respond to actions you take on the badge.&lt;br /&gt;
&lt;br /&gt;
{{Note|Note: Refreshing the OLEDs is reasonably intense on the microprocessor. If you have too many event loops triggering too often and/or too much screen activity, you can starve the badge of resources. This can produce wifi dropouts, or non-responsiveness. If you have a lot of screen activity, consider using a buffer or recording state and just doing a screen update periodically}}&lt;br /&gt;
&lt;br /&gt;
== Software reference ==&lt;br /&gt;
&lt;br /&gt;
=== MicroPython environment ===&lt;br /&gt;
&lt;br /&gt;
[https://micropython.org MicroPython docs]&lt;br /&gt;
&lt;br /&gt;
==== Special files ====&lt;br /&gt;
&lt;br /&gt;
There are two special files which are run automatically by MicroPython if they exist on the filesystem: &amp;lt;code&amp;gt;boot.py&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;boot.py&#039;&#039;&#039;: This file is run first on power up/reset. We don&#039;t modify it from what MicroPython ships with, but it&#039;s important to know it exists (and not to delete it), and is interesting to look into it to see what it does.&lt;br /&gt;
* &#039;&#039;&#039;main.py&#039;&#039;&#039;: This is run after boot.py so if you want something to automatically happen on boot/reset, this is where to put it. We use this to start up the Aiko framework, initialise the hardware (such as the network and mqtt) and start up any application that is configured inside &amp;lt;code&amp;gt;configuration/main.py&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Directory structure ====&lt;br /&gt;
&lt;br /&gt;
What&#039;s on the processor? Where does it live?&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;main.py&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;boot.py&amp;lt;/code&amp;gt; - files run on bootup&lt;br /&gt;
* &amp;lt;code&amp;gt;lib&amp;lt;/code&amp;gt; - code in here is aiko framework code and automatically in the micropython &#039;path&#039;.&lt;br /&gt;
** &amp;lt;code&amp;gt;aiko&amp;lt;/code&amp;gt; - the aiko framework&lt;br /&gt;
* &amp;lt;code&amp;gt;applications&amp;lt;/code&amp;gt; - programs to run automatically on bootup. Must have an initialise function&lt;br /&gt;
* &amp;lt;code&amp;gt;configuration&amp;lt;/code&amp;gt; - control the config of aiko using files in here&lt;br /&gt;
* &amp;lt;code&amp;gt;examples&amp;lt;/code&amp;gt; - sample code!&lt;br /&gt;
&lt;br /&gt;
You can&#039;t edit the files directly on the processor (there&#039;s no editing tooling): you edit a copy of it on your computer, then use mpfshell to &amp;lt;code&amp;gt;put&amp;lt;/code&amp;gt; it onto the badge.&lt;br /&gt;
&lt;br /&gt;
For micropython purposes, you can use the &amp;lt;code&amp;gt;import&amp;lt;/code&amp;gt; statement to import anything in the &amp;lt;code&amp;gt;lib&amp;lt;/code&amp;gt; directory without prefacing it with &amp;quot;lib&amp;quot;, anything else is imported from root.&lt;br /&gt;
For example:&lt;br /&gt;
* to import lib/aiko/net.py, you would use &amp;lt;code&amp;gt;import aiko.net&amp;lt;/code&amp;gt;&lt;br /&gt;
* to import examples/showcase.py, you would use &amp;lt;code&amp;gt;import examples.showcase&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because the aiko configuration files are, themselves, just python, you can also do &amp;lt;code&amp;gt;import configuration.main.settings&amp;lt;/code&amp;gt; where the file is in /configuration/main.py but it contains a datastructure called &#039;settings&#039;.&lt;br /&gt;
&lt;br /&gt;
=== MQTT ===&lt;br /&gt;
&lt;br /&gt;
See [[Link Swagbadge2021_MQTT]]&lt;br /&gt;
&lt;br /&gt;
=== Aiko ===&lt;br /&gt;
The Aiko Engine is what runs after boot (FreeRTOS, then microPython). Aiko provides a framework for developing applications, by providing higher level abstractions over the basic hardware, events, messaging and other conveniences. Basically, a lot of house keeping that you&#039;d end up writing yourself. After boot, there are two background threads, one looking after Wi-Fi connectivity and the other looking after MQTT connectivity.  &lt;br /&gt;
There are also three event handlers: MQTT keep-alive, firmware upgrader and the work-in-progress SwagBadge application handler.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; aiko.event.event_list.print()&lt;br /&gt;
&amp;lt;function swagbadge_handler at 0x3ffe6c70&amp;gt; every 5000 next 23099&lt;br /&gt;
&amp;lt;function upgrade_handler at 0x3ffedfa0&amp;gt; every 5000 next 23099&lt;br /&gt;
&amp;lt;function mqtt_ping_handler at 0x3ffe9820&amp;gt; every 60000 next 73672&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That last handler, which every 5 seconds is updating the title bar &amp;quot;LCA2021&amp;quot; &amp;lt;--&amp;gt; &amp;quot;SwagBadge&amp;quot; (see https://github.com/geekscape/aiko_engine_mp/blob/master/applications/swagbadge.py ).&lt;br /&gt;
&lt;br /&gt;
You can stop a handler, like this (this will stop the top bar status updater):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; import applications.swagbadge&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; aiko.event.remove_timer_handler(application.swagbadge_handler)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Replacing the swagbadge application with your own ===&lt;br /&gt;
&lt;br /&gt;
Edit configuration/main.py and set &amp;quot;application&amp;quot;: &amp;quot;application/yourcode&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Pushing new code ===&lt;br /&gt;
Occasionally you might find that the updated source code that you just used the mpfshell &amp;quot;put&amp;quot; command to transfer isn&#039;t properly stored on the ESP32 microPython flash filesystem. After rebooting, you might see unexpected errors. A simple way to check is to use the mpfshell &amp;quot;cat&amp;quot; command to check that the file was completely transferred.  &lt;br /&gt;
&lt;br /&gt;
The safest way to update code is to perform a reboot after transferring all the files. Doing a soft-reboot using Control-D doesn&#039;t take long, i.e it is faster and easier than doing a hard-reboot with the reset button. The good thing about a reboot (microPython interpreter restart) is that there is no confusion about the complete state of your system, i.e what references have been held onto from your older source code that might still be running in a thread or as an event handler (via the Aiko Engine framework).&lt;br /&gt;
&lt;br /&gt;
You can also delete all running modules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.modules.clear() &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More details in https://spectrum.chat/lca2021-swagbadge/software/safe-software-updates~ba541e3c-d8a2-41a8-ac47-71d87696de2d&lt;br /&gt;
&lt;br /&gt;
=== Reboot to shell / Force runaway code to stop ===&lt;br /&gt;
&lt;br /&gt;
It&#039;s possible to write code that will leave your badge unresponsive. Rebooting just reruns the same bad code. What to do?&lt;br /&gt;
&lt;br /&gt;
* Place a finger on each of the bottom slider pads, either side of the microprocessor. &lt;br /&gt;
* Trigger a restart by using the button on the back of the badge, or Ctrl-D in repl (if you can get into repl)&lt;br /&gt;
&lt;br /&gt;
The badge will restart but not autorun any code, just drop you back at the repl prompt. From there you can &amp;lt;code&amp;gt;put&amp;lt;/code&amp;gt; bugfixed code back onto the device.&lt;br /&gt;
&lt;br /&gt;
See https://github.com/geekscape/aiko_engine_mp/blob/a5b5593d37509df64a3dcb4cdc3d13a411152d82/main.py#L20&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Hardware reference ==&lt;br /&gt;
&lt;br /&gt;
=== OLED screens ===&lt;br /&gt;
&lt;br /&gt;
==== via MQTT ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;(oled:clear)&#039;&#039;&#039; : clears both screens&lt;br /&gt;
* &#039;&#039;&#039;(oled:log Hello World!)&#039;&#039;&#039; : writes a message along the bottom of the screens, scrolling up whatever is there out of the way&lt;br /&gt;
* &#039;&#039;&#039;(oled:pixel x y)&#039;&#039;&#039; : lights a pixel at that spot&lt;br /&gt;
* &#039;&#039;&#039;(oled:text x y This is a test!)&#039;&#039;&#039; : Puts some text at the position x,y. It will be displayed over the top of whatever&#039;s there.&lt;br /&gt;
&lt;br /&gt;
==== via API ====&lt;br /&gt;
&lt;br /&gt;
On the badge, by default the two oleds work as a single long screen, with text split across both of them. You can access a specific oled and use the underlying functions to write to them&lt;br /&gt;
&lt;br /&gt;
Library&lt;br /&gt;
* &#039;&#039;&#039;from aiko import oled&#039;&#039;&#039; # make the oled functions available for use within your code&lt;br /&gt;
&lt;br /&gt;
Globals&lt;br /&gt;
* &#039;&#039;&#039;[] oled.oleds&#039;&#039;&#039; # an array of oleds, letting you address them separately if you choose&lt;br /&gt;
* &#039;&#039;&#039;int oled.fg/oled.bg&#039;&#039;&#039; # get/set fg and bg colours (0 or 1)&lt;br /&gt;
* &#039;&#039;&#039;int oled.font_size&#039;&#039;&#039; # helpful to work out how much space a line of text will take up&lt;br /&gt;
* &#039;&#039;&#039;boolean oled.lock_title&#039;&#039;&#039; # true/false. True means the display always shows the title. False means it&#039;ll be wiped once the display is cleared.&lt;br /&gt;
&lt;br /&gt;
Functions&lt;br /&gt;
* &#039;&#039;&#039;oled.initialise()&#039;&#039;&#039; # uses configuration.oled.settings by default, normally already invoked by the base swagbadge handler&lt;br /&gt;
* &#039;&#039;&#039;oled.oleds_clear(colour)&#039;&#039;&#039; # pass in oled.bg or oled.fg for easy set. Wipes the display&lt;br /&gt;
* &#039;&#039;&#039;oled.log(text)&#039;&#039;&#039; # scroll up text to insert a new line at the bottom of the display&lt;br /&gt;
* &#039;&#039;&#039;oled.text(text, x, y, colour)&#039;&#039;&#039; # add text at the position x,y in the colour specified. Note: does not clear the contents at this spot first.&lt;br /&gt;
* &#039;&#039;&#039;oled.oleds_show()&#039;&#039;&#039; # refresh the display with the latest text/image additions&lt;br /&gt;
* &#039;&#039;&#039;oled.set_title(text)&#039;&#039;&#039; # set the title text&lt;br /&gt;
* &#039;&#039;&#039;oled.write_title()&#039;&#039;&#039; # write the title text&lt;br /&gt;
&lt;br /&gt;
Coming soon - a way to easily write images to an oled.&lt;br /&gt;
&lt;br /&gt;
=== Screen buttons ===&lt;br /&gt;
&lt;br /&gt;
If you push (gently!) on the screens, you&#039;ll discover they double as buttons: there&#039;s a small switch under each OLED that is pressed when you push down on the screen.&lt;br /&gt;
&lt;br /&gt;
{{Note|&#039;&#039;&#039;Warning&#039;&#039;&#039;: Push on the &#039;&#039;&#039;middle&#039;&#039;&#039; of the screen, not the edge. This will minimise the risk of bending... and breaking... the screen.}}&lt;br /&gt;
&lt;br /&gt;
The left screen button is pin 16. The right screen button is pin 17.&lt;br /&gt;
&lt;br /&gt;
==== via API ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from machine import Pin&lt;br /&gt;
&lt;br /&gt;
button_left = Pin(16, Pin.IN, Pin.PULL_UP)&lt;br /&gt;
button_right = Pin(17, Pin.IN, Pin.PULL_UP)&lt;br /&gt;
&lt;br /&gt;
pressed = not(button_left.value())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The button sends &amp;quot;1&amp;quot; when it&#039;s &#039;&#039;not&#039;&#039; being pressed, and &amp;quot;0&amp;quot; when it is. This is counterintuitive to most of us, so I recommend inverting the value when reading it.&lt;br /&gt;
&lt;br /&gt;
=== Sliders ===&lt;br /&gt;
&lt;br /&gt;
The sliders operate via capacitive touch. You can use them to detect if someone has their finger on the circular pads at either end (which let you treat them like buttons), or you can detect the position of the finger along the slider by checking the relative values as the capacitance changes.&lt;br /&gt;
&lt;br /&gt;
The left slider is on pins 12 (bottom) and 15 (top), right slider is on pins 14 (bottom) and 27 (top).&lt;br /&gt;
&lt;br /&gt;
More info from MicroPython about [http://docs.micropython.org/en/latest/esp32/quickref.html?highlight=touchpad#capacitive-touch capacitive touch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from machine import Pin, TouchPad&lt;br /&gt;
import aiko.common&lt;br /&gt;
&lt;br /&gt;
bottom_left = TouchPad(Pin(12))&lt;br /&gt;
top_left = TouchPad(Pin(15))&lt;br /&gt;
bottom_right = TouchPad(Pin(14))&lt;br /&gt;
top_right = TouchPad(Pin(27))&lt;br /&gt;
&lt;br /&gt;
# is this button pressed?&lt;br /&gt;
# the commons library returns true/false&lt;br /&gt;
pressed_bottom_left = common.touch_pins_check([bottom_left])&lt;br /&gt;
&lt;br /&gt;
# check where we are along the slider&lt;br /&gt;
# the &#039;read&#039; functions return an integer of the &#039;strength&#039; of the &lt;br /&gt;
# capacitance. As you move your finger between the endpoints, &lt;br /&gt;
#the relative value of the difference between them will change.&lt;br /&gt;
slider_left = bottom_left.read() - bottom_left.read()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Micropython functions&lt;br /&gt;
* &#039;&#039;&#039;touchpad.read()&#039;&#039;&#039; - gives you the current value of the sensor. It will be large when not touched (over 1000) and smaller when touched.&lt;br /&gt;
Aiko functions&lt;br /&gt;
* &#039;&#039;&#039;common.touch_pins_check(touchpad_array)&#039;&#039;&#039; - Returns true if &#039;&#039;all&#039;&#039; the touchpad sensors listed are being touched, false otherwise.&lt;br /&gt;
&lt;br /&gt;
=== SAOs (simple addons) ===&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1296</id>
		<title>Swagbadge2021 GettingStarted</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1296"/>
		<updated>2021-01-16T23:13:44Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Hardware pinout */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Getting started with the Swagbadge =&lt;br /&gt;
&lt;br /&gt;
== Support ==&lt;br /&gt;
* The [https://spectrum.chat/lca2021-swagbadge Swag Badge Spectrum chat] is a place where the badge team hangs out, ready to answer your questions.&lt;br /&gt;
&lt;br /&gt;
== My package arrived in the mail, first steps. ==&lt;br /&gt;
* Your package should contain your badge, and some other goodies! &lt;br /&gt;
** [[File:swagbadgepackage.jpg|400px|alt=Image showing the contents of the swagbag package]]&lt;br /&gt;
** Badge&lt;br /&gt;
** SAO headers (x 4)&lt;br /&gt;
** SAO proto boards (x 2)&lt;br /&gt;
** SAO tux board&lt;br /&gt;
** Lanyard&lt;br /&gt;
** Stickers&lt;br /&gt;
** Instructions&lt;br /&gt;
* Take off the protective cases to reveal the screens.&lt;br /&gt;
* Powering it up&lt;br /&gt;
** Insert a micro USB cable into the badge and connect the other end to a USB port on your computer or USB power source.&lt;br /&gt;
** A green light should glow on the rear of the board, and a title appear across the two screens.&lt;br /&gt;
* Turning it on and off again&lt;br /&gt;
** Plugging/unplugging it is fine. Usually the badge isn&#039;t running anything intensely enough that just unpowering it would cause a problem.&lt;br /&gt;
* On bootup, you should see:&lt;br /&gt;
** The OLED screens will display &amp;quot;Aiko&amp;quot; and a version number as a title&lt;br /&gt;
** It will also display something else to tell you to set up your wifi.&lt;br /&gt;
&lt;br /&gt;
== Getting it on your network ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Safety precautions we have provided&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* When using any hardware ordered off the internet, you can&#039;t be quite certain what software might be present on it. Before shipping these badges to you, we reflashed a fresh copy of MicroPython onto the Lolin32.&lt;br /&gt;
* The framework running on the badge is Aiko, which is open source.&lt;br /&gt;
* The software on the badge is available on the CCHS repository, also all open source.&lt;br /&gt;
* The badges are designed to communicate over MQTT - a lightweight standard for messaging on IoT devices, but we are aware of privacy considerations: you don&#039;t want anybody able to control your badge from afar. The swagbadge protocol provides support for encrypted messages.&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - wireless ===&lt;br /&gt;
&lt;br /&gt;
* The first time you boot your device, it won&#039;t know how to talk to your network. If it can&#039;t detect a pre-existing set of network credentials, or connect to anything it knows about, it will establish a temporary access point and prompt you to navigate to it to enter your wifi details.&lt;br /&gt;
* &#039;&#039;Note: Your device can only talk to a 2.4GHz network: it is not compatible with 5GHz WiFi.&#039;&#039;&lt;br /&gt;
* The screens on your badge will say: &amp;lt;code&amp;gt;Configure WiFi: aiko1234a12341234. Try http://192.168.4.1&amp;lt;/code&amp;gt;&lt;br /&gt;
* Use your phone or computer to connect to the wifi network on the badge. Its name starts with &amp;lt;code&amp;gt;aiko&amp;lt;/code&amp;gt; followed by some numbers/letters.&lt;br /&gt;
* Once you&#039;re connected to the badge, open a web browser to the IP address on the screens. Something like &amp;lt;code&amp;gt;http://192.168.4.1&amp;lt;/code&amp;gt;&lt;br /&gt;
* You&#039;ll be prompted to enter your wifi SSID and wifi password.&lt;br /&gt;
* Once you&#039;ve saved that, the badge will restart using the credentials you&#039;ve provided and it will shut down its wifi access point.&lt;br /&gt;
&lt;br /&gt;
Note: If you are using an Android device to link the badge to your WiFi, it will pop up a dialog to say you are switching to a network that doesn&#039;t have Internet access and ask if you want to switch back. Select &amp;quot;Keep&amp;quot; to stay on the badge&#039;s temporary access point.&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - commandline with mpfshell ===&lt;br /&gt;
&lt;br /&gt;
* If setting up via the wifi AP (access point) doesn&#039;t work, you can put a configuration file onto the badge.&lt;br /&gt;
* You&#039;ll need to start by getting [[Swagbadge2021_UpdatingSoftware|a copy of the aiko firmware, and installing mpfshell]]&lt;br /&gt;
* &#039;&#039;Note: Your device can only talk to a 2.4GHz network: it is not compatible with 5GHz.&#039;&#039;&lt;br /&gt;
* Edit aiko_engine_mp/configuration/net.py and insert the details of your SSID and password.&lt;br /&gt;
* use mpfshell: &amp;lt;code&amp;gt;mpfshell -o COM3&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;put configuration/net.py configuration/net.py&amp;lt;/code&amp;gt;&lt;br /&gt;
* fire up repl to view the console log &lt;br /&gt;
* You can now restart your device&lt;br /&gt;
* On bootup it should now talk to your network and you can see it on the console log.&lt;br /&gt;
&lt;br /&gt;
On bootup you should now see...&lt;br /&gt;
&lt;br /&gt;
= Running pre-installed applications =&lt;br /&gt;
&lt;br /&gt;
== Aiko&#039;s minimal Swagbadge application ==&lt;br /&gt;
At the moment the badge by default a basic &amp;quot;Swagbadge&amp;quot; application within the Aiko framework. This application&lt;br /&gt;
* has a thread to keep wifi running, &lt;br /&gt;
* has a thread to stay connected to (our Australian, private) mqtt server&lt;br /&gt;
* has a thread to display a rotating header across the two oleds.&lt;br /&gt;
&lt;br /&gt;
You can now talk to your badge [[Swagbadge2021_MQTT|using MQTT messages]].&lt;br /&gt;
&lt;br /&gt;
== Running other applications ==&lt;br /&gt;
At the moment, &amp;quot;swagbadge&amp;quot; is the only application that&#039;s for use with the badge. &lt;br /&gt;
&lt;br /&gt;
There are [https://github.com/geekscape/aiko_engine_mp/tree/master/applications other applications] in the repo which are for other places the Aiko framework has been used.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve written an application of your own and want to run that by default on badge startup, &lt;br /&gt;
# edit your local copy of configuration/main.py and change the value of the &amp;quot;application&amp;quot; to point to your new application.&lt;br /&gt;
# using mpfshell, &#039;put&#039; configuration/main.py and applications/your_application.py onto the badge&lt;br /&gt;
# Restart the badge&lt;br /&gt;
&lt;br /&gt;
== Running example code ==&lt;br /&gt;
There is [https://github.com/geekscape/aiko_engine_mp/tree/master/examples example code] which has a number of examples in it, including a snake game and a demo of how to use various badge functions.&lt;br /&gt;
&lt;br /&gt;
# From your commandline on your computer, use mpfshell to put whatever example code you want onto the badge.&lt;br /&gt;
# To run example code, you can use the &amp;quot;emergency stop&amp;quot; function to halt any other applications and put you in the repl.&lt;br /&gt;
## Touch both of the bottom spots on the sliders&lt;br /&gt;
## Reboot the badge&lt;br /&gt;
# Now at the repl prompt, type (replace the name of the module as appropriate for the code you want to run): &lt;br /&gt;
&lt;br /&gt;
Use examples.game_snake as example:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
from examples.game_snake import run&lt;br /&gt;
run()&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ctrl-c to halt operation and return to the repl prompt.&lt;br /&gt;
&lt;br /&gt;
= Hardware pinout =&lt;br /&gt;
&lt;br /&gt;
You can get the schematic and pin mapping on this page: https://github.com/CCHS-Melbourne/Swag-Badge/blob/master/swag-badge-schematic.pdf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- GPIO0 : left breakout pin4&lt;br /&gt;
- GPIO2 : left breakout pin3&lt;br /&gt;
&lt;br /&gt;
- GPIO4 : SCL (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO5 : SDA (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO12/15: slider #1&lt;br /&gt;
- GPIO13: left breakout pin3&lt;br /&gt;
- GPIO14/27: slider #2&lt;br /&gt;
- GPIO16: left switch  (under screen #1)&lt;br /&gt;
- GPIO17: right switch (under screen #2)&lt;br /&gt;
&lt;br /&gt;
- GPIO18: SAO3 pin3 + LB pin7&lt;br /&gt;
- GPIO23: SAO3 pin4&lt;br /&gt;
&lt;br /&gt;
- GPIO19: SAO1 pin4&lt;br /&gt;
- GPIO22: SAO1 pin3 (also onboard blue LED in the back)&lt;br /&gt;
&lt;br /&gt;
- GPIO25: SAO4 pin4 + RB pin6&lt;br /&gt;
- GPIO26: SAO4 pin3 + RB pin7&lt;br /&gt;
&lt;br /&gt;
- GPIO32: SAO2 pin3 + RB pin4 (touch pin, can be used with SAO tux foot or nose touchpad)&lt;br /&gt;
- GPIO33: SAO2 pin4 + RB pin5 (touch pin, can be used with SAO tux foot or nose touchpad)&lt;br /&gt;
&lt;br /&gt;
- GPIO34: right breakout pin3&lt;br /&gt;
- GPIO35: right breakout pin3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Extensions: Adding a SAO =&lt;br /&gt;
* provided by others&lt;br /&gt;
* build your own (linky here to our docs)&lt;br /&gt;
&lt;br /&gt;
= Extensions: Updating the software framework =&lt;br /&gt;
&lt;br /&gt;
Between when we ship the board and when it arrives, there might be some changes to the software framework (Aiko). Here&#039;s how to update it. Or perhaps you&#039;re interested in writing your own applications? &lt;br /&gt;
&lt;br /&gt;
* [[Swagbadge2021_UpdatingSoftware|Updating the Software]]&lt;br /&gt;
* [[Swagbadge2021_SoftwareDev|Writing your own badge programs]]&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_UpdatingSoftware&amp;diff=1295</id>
		<title>Swagbadge2021 UpdatingSoftware</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_UpdatingSoftware&amp;diff=1295"/>
		<updated>2021-01-16T22:07:55Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Updating the software framework =&lt;br /&gt;
&lt;br /&gt;
Swagbadge owners might want to update the software framework (Aiko). Dagbadge owners will need to put the framework onto their badge before they can use it.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s how to do that!&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
* #swagbadge or #dagbadge or any ESP32 with an OLED screen&lt;br /&gt;
* Micro-USB cable&lt;br /&gt;
* Linux, Mac OS or Linux system running Python 3&lt;br /&gt;
* Command line tools: git&lt;br /&gt;
&lt;br /&gt;
== Setting up your Windows 10 system for connecting to badge hardware ==&lt;br /&gt;
&lt;br /&gt;
How to find your serial COM port on Windows: &lt;br /&gt;
* Use the Device Manager. &lt;br /&gt;
* Under the &amp;quot;Ports&amp;quot; category, you&#039;ll see one or more entries. Hopefully one of which is your badge! It will tell you what Port it is on. &lt;br /&gt;
* If you can&#039;t see your badge, you might need to go up to the View menu and use &amp;quot;Show hidden devices&amp;quot; and see if that helps.&lt;br /&gt;
&lt;br /&gt;
Windows 10 may automatically discover your #swagbadge USB hardware and automatically install the correct USB serial hardware driver, or if nothing still shows up, you might need to update your USB drivers for supporting the USB hardware CP210x on your #swagbadge, please follow these instructions:&lt;br /&gt;
* Download the CP210x drivers from [https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers Silicon Labs Windows Universal Driver]&lt;br /&gt;
* Unpack the zip file&lt;br /&gt;
* Follow the Silicon Labs instructions for [https://www.silabs.com/documents/public/application-notes/AN335.pdf INF only install] (Section 5 on page 9)&lt;br /&gt;
&lt;br /&gt;
By this point, you have know the serial COM port that your #swagbadge is connected to, e.g COM4&lt;br /&gt;
&lt;br /&gt;
== Setting up your Mac OS system for connecting to #swagbadge hardware ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How to find your serial COM port on OS X: &lt;br /&gt;
&lt;br /&gt;
    $ ls /dev/tty.usb*&lt;br /&gt;
&lt;br /&gt;
Unless you have lot of dev boards (or maybe a phone) plugged in you should just see a single filename there.&lt;br /&gt;
Use this (without the `/dev/` prefix) when using the `open` command in `mpfshell`&lt;br /&gt;
&lt;br /&gt;
To get a working `mpfshell` install a recent version of Python (Python3.8 is known to work) using a installed DMG.&lt;br /&gt;
Then create a *venv* and install the necessary tools using pip.&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
    $ mkdir swag&lt;br /&gt;
    $ cd swag&lt;br /&gt;
    $ python3.8 -m venv env&lt;br /&gt;
    $ ./env/bin/pip install esptool mpfshell&lt;br /&gt;
&lt;br /&gt;
You can then run `mpfshell` to connect:&lt;br /&gt;
&lt;br /&gt;
    $ ./env/bin/mpfshell&lt;br /&gt;
    mpfs [/]&amp;gt; open &amp;lt;your device node as found previously&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setting up your Linux system for connecting to #swagbadge hardware ==&lt;br /&gt;
[Link other instructions here]&lt;br /&gt;
&lt;br /&gt;
== Setting up your Windows 10 system for installing #swagbadge firmware == &lt;br /&gt;
&lt;br /&gt;
* Install [https://docs.conda.io/en/latest/miniconda.html Miniconda3] to create a specific Python development environment. (Note we are using Python3 not Python2)&lt;br /&gt;
* Create specific Python 3 environment for playing around with your #swagbadge&lt;br /&gt;
** Start an Anaconda Powershell Prompt (aka Windows Terminal)&lt;br /&gt;
** &amp;lt;code&amp;gt;conda create --yes -n swagbadge python=3&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;conda activate swagbadge&amp;lt;/code&amp;gt;&lt;br /&gt;
* Your command prompt should now look like: &amp;lt;code&amp;gt;(swagbadge) C:\Users\[Username]&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Install some python tools to let us prepare and communicate with the badge&lt;br /&gt;
** &amp;lt;code&amp;gt;pip install esptool mpfshell&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To test that the required tools are installed, trying running the following commands&lt;br /&gt;
** &amp;lt;code&amp;gt;esptool&amp;lt;/code&amp;gt;  # Should show you help on running the esptool&lt;br /&gt;
** &amp;lt;code&amp;gt;mpfshell&amp;lt;/code&amp;gt;  # Should show three lines of output&lt;br /&gt;
*** &amp;lt;code&amp;gt;exit&amp;lt;/code&amp;gt;  #  To exit mpfshell&lt;br /&gt;
&lt;br /&gt;
== Download #swagbadge (Aiko Engine) firmware ==&lt;br /&gt;
&lt;br /&gt;
Within your Anaconda Prompt session, change directory to where you’d like the #swagbadge software to be downloaded, for example:&lt;br /&gt;
* &amp;lt;code&amp;gt;cd $HOME/software&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Download #swagbadge firmware:&lt;br /&gt;
* &amp;lt;code&amp;gt;git clone https://github.com/geekscape/aiko_engine_mp.git&amp;lt;/code&amp;gt; # NOTE: this URL will change once we&#039;re live&lt;br /&gt;
* &amp;lt;code&amp;gt;cd aiko_engine_mp&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Install MicroPython&lt;br /&gt;
* Create a directory to hold the MicroPython firmware, such as aiko_engine_mp/firmware/&lt;br /&gt;
* &amp;lt;code&amp;gt;mkdir firmware&amp;lt;/code&amp;gt;&lt;br /&gt;
* Using your web browser, download: [http://micropython.org/resources/firmware/esp32-idf4-20200902-v1.13.bin esp32-idf4-20200902-v1.13.bin] (mouse right button click → [Save As …]  saving the MicroPython firmware in the firmware directory you just made.&lt;br /&gt;
** The [http://micropython.org/download/ MicroPython download list] has a link to a bunch of firmware drivers, we are using the one for the esp32 device, with the latest 1.4 generic&lt;br /&gt;
&lt;br /&gt;
Erase #swagbadge LoLin-Lite ESP32 flash memory&lt;br /&gt;
* &amp;lt;code&amp;gt;esptool --chip esp32 --port COM3 erase_flash&amp;lt;/code&amp;gt; # adjust the port to suit.&lt;br /&gt;
* You’ll know it’s worked, if the output finishes with “Hard resetting via RTS pin…”&lt;br /&gt;
&lt;br /&gt;
Install microPython on the badge&lt;br /&gt;
* &amp;lt;code&amp;gt;esptool --chip esp32 --port COM3 --baud 460800 write_flash -z 0x1000 firmware\esp32-idf4-20200902-v1.13.bin&amp;lt;/code&amp;gt; #adjust port and firmware location if necessary&lt;br /&gt;
* You’ll know it’s worked, if the output finishes with “Hard resetting via RTS pin…”&lt;br /&gt;
&lt;br /&gt;
Test that the software is installed correctly by using mpfshell&lt;br /&gt;
* &amp;lt;code&amp;gt;mpfshell -o COM3&amp;lt;/code&amp;gt; # Adjust port to suit&lt;br /&gt;
* If it has made a connection to your badge, you will see it say&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;Connected to esp32&lt;br /&gt;
** Micropython File Shell v0.9.1, sw@kaltpost.de **&lt;br /&gt;
-- Running on Python 3.8 using PySerial 3.4 --&lt;br /&gt;
mpfs [/]&amp;gt; &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using mpfshell ==&lt;br /&gt;
&lt;br /&gt;
mpfshell has two functions: it lets you put files on/off the device, and it can give you a python shell to execute code on the device.&lt;br /&gt;
* Getting files on/off the device is a bit like commandline ftp&lt;br /&gt;
** ls - looks at the files on your micropython device&lt;br /&gt;
** lls - looks at the files on your local computer in the current directory&lt;br /&gt;
** put - puts a file to the device&lt;br /&gt;
** cat - shows you the contents of the file&lt;br /&gt;
** help() - gives you more information on the commands&lt;br /&gt;
** repl - opens up the python shell on the badge&lt;br /&gt;
&lt;br /&gt;
Note: To get out of repl, use Ctrl-Q (on Windows) which drops you back into mpfshell&lt;br /&gt;
&lt;br /&gt;
A little program to say hello world!&lt;br /&gt;
* &amp;lt;code&amp;gt; &amp;gt;&amp;gt;&amp;gt; print(&amp;quot;hello world&amp;quot;)&amp;lt;/code&amp;gt;&lt;br /&gt;
* Output: &amp;lt;code&amp;gt;hello world&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A little program to turn the blue light on the board on and off (this is on the underside of the Swagbadge, visible through a circular cutout)&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&amp;gt;&amp;gt;&amp;gt; import machine&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; pin22=machine.Pin(22, machine.Pin.OUT, machine.Pin.PULL_UP)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; pin22.value(0) &lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; pin22.value(1)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Saving your private key ==&lt;br /&gt;
&lt;br /&gt;
Use mpfshell to get the file: `configuration/keys.db`.&lt;br /&gt;
&lt;br /&gt;
== Putting the Aiko framework onto the device, using mpfshell == &lt;br /&gt;
* &amp;lt;code&amp;gt;mpfshell COM5 -s scripts\aiko.mpf&amp;lt;/code&amp;gt; #run from within the aiko_framework_mp directory&lt;br /&gt;
&lt;br /&gt;
=== Windows only: Patch mpfshell ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note!&#039;&#039; mpfshell needs a patch applied to let it run a script under Windows.&lt;br /&gt;
&lt;br /&gt;
* Inside &amp;lt;code&amp;gt;C:/users/USERNAME/Miniconda2/envs/swagbadge/Lib/site-packages/mp&amp;lt;/code&amp;gt;&lt;br /&gt;
* edit &amp;lt;code&amp;gt;mpfshell.py&amp;lt;/code&amp;gt;&lt;br /&gt;
* Search for &amp;lt;code&amp;gt;elif args.script is not None:&amp;lt;/code&amp;gt;, around line 796&lt;br /&gt;
* between that line and the next, insert two lines. It should look like:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
    elif args.script is not None:&lt;br /&gt;
&lt;br /&gt;
        if platform.system() == &amp;quot;Windows&amp;quot;:  #INSERT THIS LINE&lt;br /&gt;
            mpfs.use_rawinput = True        #INSERT THIS LINE&lt;br /&gt;
&lt;br /&gt;
        f = open(args.script, &amp;quot;r&amp;quot;)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* Python is very particular about spacing. The rest of the code uses 4 spaces for indents so follow suit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Software development =&lt;br /&gt;
&lt;br /&gt;
== Aiko ==&lt;br /&gt;
The Aiko Engine is what runs after boot (FreeRTOS, then microPython). Aiko provides a framework for developing applications, by providing higher level abstractions over the basic hardware, events, messaging and other conveniences. Basically, a lot of house keeping that you&#039;d end up writing yourself. After boot, there are two background threads, one looking after Wi-Fi connectivity and the other looking after MQTT connectivity.  &lt;br /&gt;
There are also three event handlers: MQTT keep-alive, firmware upgrader and the work-in-progress SwagBadge application handler.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; aiko.event.event_list.print()&lt;br /&gt;
&amp;lt;function swagbadge_handler at 0x3ffe6c70&amp;gt; every 5000 next 23099&lt;br /&gt;
&amp;lt;function upgrade_handler at 0x3ffedfa0&amp;gt; every 5000 next 23099&lt;br /&gt;
&amp;lt;function mqtt_ping_handler at 0x3ffe9820&amp;gt; every 60000 next 73672&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That last handler, which every 5 seconds is updating the title bar &amp;quot;LCA2021&amp;quot; &amp;lt;--&amp;gt; &amp;quot;SwagBadge&amp;quot; (see https://github.com/geekscape/aiko_engine_mp/blob/master/applications/swagbadge.py ).&lt;br /&gt;
&lt;br /&gt;
You can stop a handler, like this (this will stop the top bar status updater):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; import applications.swagbadge&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; aiko.event.remove_timer_handler(application.swagbadge_handler)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the swagbadge application with your own ==&lt;br /&gt;
&lt;br /&gt;
Edit configuration/main.py and set &amp;quot;application&amp;quot;: &amp;quot;application/yourcode&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Pushing new code ==&lt;br /&gt;
Occasionally you might find that the updated source code that you just used the mpfshell &amp;quot;put&amp;quot; command to transfer isn&#039;t properly stored on the ESP32 microPython flash filesystem. After rebooting, you might see unexpected errors. A simple way to check is to use the mpfshell &amp;quot;cat&amp;quot; command to check that the file was completely transferred.  &lt;br /&gt;
&lt;br /&gt;
The safest way to update code is to perform a reboot after transferring all the files. Doing a soft-reboot using Control-D doesn&#039;t take long, i.e it is faster and easier than doing a hard-reboot with the reset button. The good thing about a reboot (microPython interpreter restart) is that there is no confusion about the complete state of your system, i.e what references have been held onto from your older source code that might still be running in a thread or as an event handler (via the Aiko Engine framework).&lt;br /&gt;
&lt;br /&gt;
You can also delete all running modules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.modules.clear() &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More details in https://spectrum.chat/lca2021-swagbadge/software/safe-software-updates~ba541e3c-d8a2-41a8-ac47-71d87696de2d&lt;br /&gt;
&lt;br /&gt;
== Reboot to shell / Force runaway code to stop ==&lt;br /&gt;
&lt;br /&gt;
It&#039;s possible to write code that will leave your badge unresponsive. Rebooting just reruns the same bad code. What to do?&lt;br /&gt;
&lt;br /&gt;
* Place a finger on each of the bottom slider pads, either side of the microprocessor. &lt;br /&gt;
* Trigger a restart by using the button on the back of the badge, or Ctrl-D in repl (if you can get into repl)&lt;br /&gt;
&lt;br /&gt;
The badge will restart but not autorun any code, just drop you back at the repl prompt. From there you can &amp;lt;code&amp;gt;put&amp;lt;/code&amp;gt; bugfixed code back onto the device.&lt;br /&gt;
&lt;br /&gt;
See https://github.com/geekscape/aiko_engine_mp/blob/a5b5593d37509df64a3dcb4cdc3d13a411152d82/main.py#L20&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1294</id>
		<title>Swagbadge2021 GettingStarted</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1294"/>
		<updated>2021-01-16T06:15:54Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Hardware pinout */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Getting started with the Swagbadge =&lt;br /&gt;
&lt;br /&gt;
== Support ==&lt;br /&gt;
* The [https://spectrum.chat/lca2021-swagbadge Swag Badge Spectrum chat] is a place where the badge team hangs out, ready to answer your questions.&lt;br /&gt;
&lt;br /&gt;
== My package arrived in the mail, first steps. ==&lt;br /&gt;
* Your package should contain your badge, and some other goodies! &lt;br /&gt;
** [[File:swagbadgepackage.jpg|400px|alt=Image showing the contents of the swagbag package]]&lt;br /&gt;
** Badge&lt;br /&gt;
** SAO headers (x 4)&lt;br /&gt;
** SAO proto boards (x 2)&lt;br /&gt;
** SAO tux board&lt;br /&gt;
** Lanyard&lt;br /&gt;
** Stickers&lt;br /&gt;
** Instructions&lt;br /&gt;
* Take off the protective cases to reveal the screens.&lt;br /&gt;
* Powering it up&lt;br /&gt;
** Insert a micro USB cable into the badge and connect the other end to a USB port on your computer or USB power source.&lt;br /&gt;
** A green light should glow on the rear of the board, and a title appear across the two screens.&lt;br /&gt;
* Turning it on and off again&lt;br /&gt;
** Plugging/unplugging it is fine. Usually the badge isn&#039;t running anything intensely enough that just unpowering it would cause a problem.&lt;br /&gt;
* On bootup, you should see:&lt;br /&gt;
** The OLED screens will display &amp;quot;Aiko&amp;quot; and a version number as a title&lt;br /&gt;
** It will also display something else to tell you to set up your wifi.&lt;br /&gt;
&lt;br /&gt;
== Getting it on your network ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Safety precautions we have provided&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* When using any hardware ordered off the internet, you can&#039;t be quite certain what software might be present on it. Before shipping these badges to you, we reflashed a fresh copy of MicroPython onto the Lolin32.&lt;br /&gt;
* The framework running on the badge is Aiko, which is open source.&lt;br /&gt;
* The software on the badge is available on the CCHS repository, also all open source.&lt;br /&gt;
* The badges are designed to communicate over MQTT - a lightweight standard for messaging on IoT devices, but we are aware of privacy considerations: you don&#039;t want anybody able to control your badge from afar. The swagbadge protocol provides support for encrypted messages.&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - wireless ===&lt;br /&gt;
&lt;br /&gt;
* The first time you boot your device, it won&#039;t know how to talk to your network. If it can&#039;t detect a pre-existing set of network credentials, or connect to anything it knows about, it will establish a temporary access point and prompt you to navigate to it to enter your wifi details.&lt;br /&gt;
* &#039;&#039;Note: Your device can only talk to a 2.4GHz network: it is not compatible with 5GHz WiFi.&#039;&#039;&lt;br /&gt;
* The screens on your badge will say: &amp;lt;code&amp;gt;Configure WiFi: aiko1234a12341234. Try http://192.168.4.1&amp;lt;/code&amp;gt;&lt;br /&gt;
* Use your phone or computer to connect to the wifi network on the badge. Its name starts with &amp;lt;code&amp;gt;aiko&amp;lt;/code&amp;gt; followed by some numbers/letters.&lt;br /&gt;
* Once you&#039;re connected to the badge, open a web browser to the IP address on the screens. Something like &amp;lt;code&amp;gt;http://192.168.4.1&amp;lt;/code&amp;gt;&lt;br /&gt;
* You&#039;ll be prompted to enter your wifi SSID and wifi password.&lt;br /&gt;
* Once you&#039;ve saved that, the badge will restart using the credentials you&#039;ve provided and it will shut down its wifi access point.&lt;br /&gt;
&lt;br /&gt;
Note: If you are using an Android device to link the badge to your WiFi, it will pop up a dialog to say you are switching to a network that doesn&#039;t have Internet access and ask if you want to switch back. Select &amp;quot;Keep&amp;quot; to stay on the badge&#039;s temporary access point.&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - commandline with mpfshell ===&lt;br /&gt;
&lt;br /&gt;
* If setting up via the wifi AP (access point) doesn&#039;t work, you can put a configuration file onto the badge.&lt;br /&gt;
* You&#039;ll need to start by getting [[Swagbadge2021_UpdatingSoftware|a copy of the aiko firmware, and installing mpfshell]]&lt;br /&gt;
* &#039;&#039;Note: Your device can only talk to a 2.4GHz network: it is not compatible with 5GHz.&#039;&#039;&lt;br /&gt;
* Edit aiko_engine_mp/configuration/net.py and insert the details of your SSID and password.&lt;br /&gt;
* use mpfshell: &amp;lt;code&amp;gt;mpfshell -o COM3&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;put configuration/net.py configuration/net.py&amp;lt;/code&amp;gt;&lt;br /&gt;
* fire up repl to view the console log &lt;br /&gt;
* You can now restart your device&lt;br /&gt;
* On bootup it should now talk to your network and you can see it on the console log.&lt;br /&gt;
&lt;br /&gt;
On bootup you should now see...&lt;br /&gt;
&lt;br /&gt;
= Running pre-installed applications =&lt;br /&gt;
&lt;br /&gt;
== Aiko&#039;s minimal Swagbadge application ==&lt;br /&gt;
At the moment the badge by default a basic &amp;quot;Swagbadge&amp;quot; application within the Aiko framework. This application&lt;br /&gt;
* has a thread to keep wifi running, &lt;br /&gt;
* has a thread to stay connected to (our Australian, private) mqtt server&lt;br /&gt;
* has a thread to display a rotating header across the two oleds.&lt;br /&gt;
&lt;br /&gt;
You can now talk to your badge [[Swagbadge2021_MQTT|using MQTT messages]].&lt;br /&gt;
&lt;br /&gt;
== Running other applications ==&lt;br /&gt;
At the moment, &amp;quot;swagbadge&amp;quot; is the only application that&#039;s for use with the badge. &lt;br /&gt;
&lt;br /&gt;
There are [https://github.com/geekscape/aiko_engine_mp/tree/master/applications other applications] in the repo which are for other places the Aiko framework has been used.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve written an application of your own and want to run that by default on badge startup, &lt;br /&gt;
# edit your local copy of configuration/main.py and change the value of the &amp;quot;application&amp;quot; to point to your new application.&lt;br /&gt;
# using mpfshell, &#039;put&#039; configuration/main.py and applications/your_application.py onto the badge&lt;br /&gt;
# Restart the badge&lt;br /&gt;
&lt;br /&gt;
== Running example code ==&lt;br /&gt;
There is [https://github.com/geekscape/aiko_engine_mp/tree/master/examples example code] which has a number of examples in it, including a snake game and a demo of how to use various badge functions.&lt;br /&gt;
&lt;br /&gt;
# From your commandline on your computer, use mpfshell to put whatever example code you want onto the badge.&lt;br /&gt;
# To run example code, you can use the &amp;quot;emergency stop&amp;quot; function to halt any other applications and put you in the repl.&lt;br /&gt;
## Touch both of the bottom spots on the sliders&lt;br /&gt;
## Reboot the badge&lt;br /&gt;
# Now at the repl prompt, type (replace the name of the module as appropriate for the code you want to run): &lt;br /&gt;
&lt;br /&gt;
Use examples.game_snake as example:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
from examples.game_snake import run&lt;br /&gt;
run()&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ctrl-c to halt operation and return to the repl prompt.&lt;br /&gt;
&lt;br /&gt;
= Hardware pinout =&lt;br /&gt;
&lt;br /&gt;
You can get the schematic and pin mapping on this page: https://github.com/CCHS-Melbourne/Swag-Badge/blob/master/swag-badge-schematic.pdf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- GPIO0 : left breakout pin4&lt;br /&gt;
- GPIO2 : left breakout pin3&lt;br /&gt;
&lt;br /&gt;
- GPIO4 : SCL  (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO5 : SDA (shared across all SAO connectors and the screens)&lt;br /&gt;
- GPIO12/15: slider #1&lt;br /&gt;
- GPIO13: left breakout pin3&lt;br /&gt;
- GPIO14/27: slider #2&lt;br /&gt;
- GPIO16: left switch  (under screen #1)&lt;br /&gt;
- GPIO17: right switch (under screen #2)&lt;br /&gt;
&lt;br /&gt;
- GPIO18: SAO3 pin3 + LB pin7&lt;br /&gt;
- GPIO23: SAO3 pin4&lt;br /&gt;
&lt;br /&gt;
- GPIO19: SAO1 pin4&lt;br /&gt;
- GPIO22: SAO1 pin3&lt;br /&gt;
&lt;br /&gt;
- GPIO25: SAO4 pin4 + RB pin3&lt;br /&gt;
- GPIO26: SAO4 pin3 + RB pin4&lt;br /&gt;
&lt;br /&gt;
- GPIO32: SAO2 pin3 + RB pin4&lt;br /&gt;
- GPIO33: SAO2 pin4 + RB pin3&lt;br /&gt;
&lt;br /&gt;
- GPIO34: right breakout pin3&lt;br /&gt;
- GPIO35: right breakout pin3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Extensions: Adding a SAO =&lt;br /&gt;
* provided by others&lt;br /&gt;
* build your own (linky here to our docs)&lt;br /&gt;
&lt;br /&gt;
= Extensions: Updating the software framework =&lt;br /&gt;
&lt;br /&gt;
Between when we ship the board and when it arrives, there might be some changes to the software framework (Aiko). Here&#039;s how to update it. Or perhaps you&#039;re interested in writing your own applications? &lt;br /&gt;
&lt;br /&gt;
* [[Swagbadge2021_UpdatingSoftware|Updating the Software]]&lt;br /&gt;
* [[Swagbadge2021_SoftwareDev|Writing your own badge programs]]&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1290</id>
		<title>Swagbadge2021 GettingStarted</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1290"/>
		<updated>2021-01-16T02:14:23Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Running example code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Getting started with the Swagbadge =&lt;br /&gt;
&lt;br /&gt;
== Support ==&lt;br /&gt;
* The [https://spectrum.chat/lca2021-swagbadge Swag Badge Spectrum chat] is a place where the badge team hangs out, ready to answer your questions.&lt;br /&gt;
&lt;br /&gt;
== My package arrived in the mail, first steps. ==&lt;br /&gt;
* Your package should contain your badge, and some other goodies! &lt;br /&gt;
** [[File:swagbadgepackage.jpg|400px|alt=Image showing the contents of the swagbag package]]&lt;br /&gt;
** Badge&lt;br /&gt;
** SAO headers (x 4)&lt;br /&gt;
** SAO proto boards (x 2)&lt;br /&gt;
** SAO tux board&lt;br /&gt;
** Lanyard&lt;br /&gt;
** Stickers&lt;br /&gt;
** Instructions&lt;br /&gt;
* Take off the protective cases to reveal the screens.&lt;br /&gt;
* Powering it up&lt;br /&gt;
** Insert a micro USB cable into the badge and connect the other end to a USB port on your computer or USB power source.&lt;br /&gt;
** A green light should glow on the rear of the board, and a title appear across the two screens.&lt;br /&gt;
* Turning it on and off again&lt;br /&gt;
** Plugging/unplugging it is fine. Usually the badge isn&#039;t running anything intensely enough that just unpowering it would cause a problem.&lt;br /&gt;
* On bootup, you should see:&lt;br /&gt;
** The OLED screens will display &amp;quot;Aiko&amp;quot; and a version number as a title&lt;br /&gt;
** It will also display something else to tell you to set up your wifi.&lt;br /&gt;
&lt;br /&gt;
== Getting it on your network ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Safety precautions we have provided&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* When using any hardware ordered off the internet, you can&#039;t be quite certain what software might be present on it. Before shipping these badges to you, we reflashed a fresh copy of MicroPython onto the Lolin32.&lt;br /&gt;
* The framework running on the badge is Aiko, which is open source.&lt;br /&gt;
* The software on the badge is available on the CCHS repository, also all open source.&lt;br /&gt;
* The badges are designed to communicate over MQTT - a lightweight standard for messaging on IoT devices, but we are aware of privacy considerations: you don&#039;t want anybody able to control your badge from afar. The swagbadge protocol provides support for encrypted messages.&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - wireless ===&lt;br /&gt;
&lt;br /&gt;
* The first time you boot your device, it won&#039;t know how to talk to your network. If it can&#039;t detect a pre-existing set of network credentials, or connect to anything it knows about, it will establish a temporary access point and prompt you to navigate to it to enter your wifi details.&lt;br /&gt;
* &#039;&#039;Note: Your device can only talk to a 2.4GHz network: it is not compatible with 5GHz WiFi.&#039;&#039;&lt;br /&gt;
* The screens on your badge will say: &amp;lt;code&amp;gt;Configure WiFi: aiko1234a12341234. Try http://192.168.4.1&amp;lt;/code&amp;gt;&lt;br /&gt;
* Use your phone or computer to connect to the wifi network on the badge. Its name starts with &amp;lt;code&amp;gt;aiko&amp;lt;/code&amp;gt; followed by some numbers/letters.&lt;br /&gt;
* Once you&#039;re connected to the badge, open a web browser to the IP address on the screens. Something like &amp;lt;code&amp;gt;http://192.168.4.1&amp;lt;/code&amp;gt;&lt;br /&gt;
* You&#039;ll be prompted to enter your wifi SSID and wifi password.&lt;br /&gt;
* Once you&#039;ve saved that, the badge will restart using the credentials you&#039;ve provided and it will shut down its wifi access point.&lt;br /&gt;
&lt;br /&gt;
Note: If you are using an Android device to link the badge to your WiFi, it will pop up a dialog to say you are switching to a network that doesn&#039;t have Internet access and ask if you want to switch back. Select &amp;quot;Keep&amp;quot; to stay on the badge&#039;s temporary access point.&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - commandline with mpfshell ===&lt;br /&gt;
&lt;br /&gt;
* If setting up via the wifi AP (access point) doesn&#039;t work, you can put a configuration file onto the badge.&lt;br /&gt;
* You&#039;ll need to start by getting [[Swagbadge2021_UpdatingSoftware|a copy of the aiko firmware, and installing mpfshell]]&lt;br /&gt;
* &#039;&#039;Note: Your device can only talk to a 2.4GHz network: it is not compatible with 5GHz.&#039;&#039;&lt;br /&gt;
* Edit aiko_engine_mp/configuration/net.py and insert the details of your SSID and password.&lt;br /&gt;
* use mpfshell: &amp;lt;code&amp;gt;mpfshell -o COM3&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;put configuration/net.py configuration/net.py&amp;lt;/code&amp;gt;&lt;br /&gt;
* fire up repl to view the console log &lt;br /&gt;
* You can now restart your device&lt;br /&gt;
* On bootup it should now talk to your network and you can see it on the console log.&lt;br /&gt;
&lt;br /&gt;
On bootup you should now see...&lt;br /&gt;
&lt;br /&gt;
= Running pre-installed applications =&lt;br /&gt;
&lt;br /&gt;
== Aiko&#039;s minimal Swagbadge application ==&lt;br /&gt;
At the moment the badge by default a basic &amp;quot;Swagbadge&amp;quot; application within the Aiko framework. This application&lt;br /&gt;
* has a thread to keep wifi running, &lt;br /&gt;
* has a thread to stay connected to (our Australian, private) mqtt server&lt;br /&gt;
* has a thread to display a rotating header across the two oleds.&lt;br /&gt;
&lt;br /&gt;
You can now talk to your badge [[Swagbadge2021_MQTT|using MQTT messages]].&lt;br /&gt;
&lt;br /&gt;
== Running other applications ==&lt;br /&gt;
At the moment, &amp;quot;swagbadge&amp;quot; is the only application that&#039;s for use with the badge. &lt;br /&gt;
&lt;br /&gt;
There are [https://github.com/geekscape/aiko_engine_mp/tree/master/applications other applications] in the repo which are for other places the Aiko framework has been used.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve written an application of your own and want to run that by default on badge startup, &lt;br /&gt;
# edit your local copy of configuration/main.py and change the value of the &amp;quot;application&amp;quot; to point to your new application.&lt;br /&gt;
# using mpfshell, &#039;put&#039; configuration/main.py and applications/your_application.py onto the badge&lt;br /&gt;
# Restart the badge&lt;br /&gt;
&lt;br /&gt;
== Running example code ==&lt;br /&gt;
There is [https://github.com/geekscape/aiko_engine_mp/tree/master/examples example code] which has a number of examples in it, including a snake game and a demo of how to use various badge functions.&lt;br /&gt;
&lt;br /&gt;
# From your commandline on your computer, use mpfshell to put whatever example code you want onto the badge.&lt;br /&gt;
# To run example code, you can use the &amp;quot;emergency stop&amp;quot; function to halt any other applications and put you in the repl.&lt;br /&gt;
## Touch both of the bottom spots on the sliders&lt;br /&gt;
## Reboot the badge&lt;br /&gt;
# Now at the repl prompt, type (replace the name of the module as appropriate for the code you want to run): &lt;br /&gt;
&lt;br /&gt;
Use examples.game_snake as example:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
from examples.game_snake import run&lt;br /&gt;
run()&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ctrl-c to halt operation and return to the repl prompt.&lt;br /&gt;
&lt;br /&gt;
= Hardware pinout =&lt;br /&gt;
&lt;br /&gt;
You can get the schematic and pin mapping on this page: https://github.com/CCHS-Melbourne/Swag-Badge/blob/master/swag-badge-schematic.pdf&lt;br /&gt;
&lt;br /&gt;
= Extensions: Adding a SAO =&lt;br /&gt;
* provided by others&lt;br /&gt;
* build your own (linky here to our docs)&lt;br /&gt;
&lt;br /&gt;
= Extensions: Updating the software framework =&lt;br /&gt;
&lt;br /&gt;
Between when we ship the board and when it arrives, there might be some changes to the software framework (Aiko). Here&#039;s how to update it. Or perhaps you&#039;re interested in writing your own applications? &lt;br /&gt;
&lt;br /&gt;
* [[Swagbadge2021_UpdatingSoftware|Updating the Software]]&lt;br /&gt;
* [[Swagbadge2021_SoftwareDev|Writing your own badge programs]]&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_MQTT&amp;diff=1289</id>
		<title>Swagbadge2021 MQTT</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_MQTT&amp;diff=1289"/>
		<updated>2021-01-15T20:26:26Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Making your badge perform */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Controlling your badge over MQTT =&lt;br /&gt;
&lt;br /&gt;
== About the LCA Swagbadge MQTT server ==&lt;br /&gt;
&lt;br /&gt;
The badges have MQTT configured to talk to a dedicated server hosted by Andy Gelme, one of the OHMC organisers. We have done this for security and privacy reasons, and because it gives us an Australian server so it&#039;s faster.&lt;br /&gt;
&lt;br /&gt;
This server is at &amp;lt;code&amp;gt;101.181.46.180&amp;lt;/code&amp;gt;, the configuration for which is held on the badge at [https://github.com/geekscape/aiko_engine_mp/blob/master/configuration/mqtt.py configuration/mqtt.py]. The server has some special features:&lt;br /&gt;
* The &#039;&#039;upgrade/&#039;&#039; topic path prefix is public read: only Jon and Andy can update it.&lt;br /&gt;
* The &#039;&#039;aiko/&#039;&#039; topic path prefix is public read/write&lt;br /&gt;
* We have some server monitoring to look for things snooping for all the channels, or who aren&#039;t using aiko/on a badge, and mitigations in the event a badge goes beserk and starts a spamming DOS attack.&lt;br /&gt;
&lt;br /&gt;
You are welcome to change which MQTT server your badge uses, by updating the mqtt.py configuration file. Some publicly hosted alternatives are provided (commented out) in the config.&lt;br /&gt;
&lt;br /&gt;
== Making your badge perform ==&lt;br /&gt;
&lt;br /&gt;
The easiest thing to do is send messages to show up on your screens.&lt;br /&gt;
&lt;br /&gt;
# Install an mqtt client on your machine&lt;br /&gt;
# Connect to the mqtt server (if you forget what it is, the IP address is shown on bootup)&lt;br /&gt;
# Using your badge&#039;s topic (public/esp32_your_badge_id/0/in) send it a message&lt;br /&gt;
&lt;br /&gt;
Messages are usually in the form of &amp;lt;code&amp;gt;(component:command arguments)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
mosquitto_sub -h 101.181.46.180 -t public/esp32_id/0 &amp;amp;   &amp;lt;&amp;lt; does this receive anything?&lt;br /&gt;
&lt;br /&gt;
mosquitto_pub -h 101.181.46.180 -t public/esp32_id/0/in -m &amp;quot;(oled:clear)&amp;quot;  &lt;br /&gt;
&lt;br /&gt;
mosquitto_pub -h 101.181.46.180 -t public/esp32_id/0/in -m &amp;quot;(oled:pixel 64 32)&amp;quot;  &lt;br /&gt;
&lt;br /&gt;
mosquitto_pub -h 101.181.46.180 -t public/esp32_id/0/in -m &amp;quot;(oled:text 0 50 Hello World)&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== OLED messages ===&lt;br /&gt;
;(oled&amp;amp;#58;clear)&lt;br /&gt;
: clears both screens&lt;br /&gt;
;(oled&amp;amp;#58;log Hello World!)&lt;br /&gt;
: writes a message along the bottom of the screens, scrolling up whatever is there out of the way&lt;br /&gt;
; (oled&amp;amp;#58;pixel x y)&lt;br /&gt;
: lights a pixel at that spot&lt;br /&gt;
; (oled&amp;amp;#58;text x y This is a test !)&lt;br /&gt;
: Puts some text at the position x,y. It will be displayed over the top of whatever&#039;s there.&lt;br /&gt;
&lt;br /&gt;
If you&#039;d like to make your application MQTT aware, take a look at the [https://github.com/geekscape/aiko_engine_mp/blob/master/lib/aiko/oled.py oled code].&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=SwagBadge2021&amp;diff=1288</id>
		<title>SwagBadge2021</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=SwagBadge2021&amp;diff=1288"/>
		<updated>2021-01-15T06:08:07Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Getting started */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Swagbadge for [https://lca2021.linux.org.au LCA2021]: Welcome! =&lt;br /&gt;
&lt;br /&gt;
== Status, About us, Contact us ==&lt;br /&gt;
* [https://spectrum.chat/lca2021-swagbadge Swagbadge/Dagbadge spectrum forums]: talk to the team, get help!&lt;br /&gt;
* &#039;&#039;&#039;[[SwagBadge2021 Status, blog and timeline]]: Read for regular project updates and history&#039;&#039;&#039;&lt;br /&gt;
* [https://twitter.com/swagbadge2021 Twitter @swagbadge]: Follow for project notifications.  HashTags: &#039;&#039;#swagbadge, #lca2021&#039;&#039;&lt;br /&gt;
* [https://diyodemag.com/columns/swagbadge_dagbadge_badge_ohmc_linux_conference DIYODE magazine issue 41, December 2020 article] on the Swagbadge&lt;br /&gt;
&lt;br /&gt;
== Getting started ==&lt;br /&gt;
* [https://spectrum.chat/lca2021-swagbadge SwagBadge Spectrum chat]: Chat system where the SwagBadge team hang out to help you with your badge&lt;br /&gt;
* [[Swagbadge2021_Newcomers|Newcomers guide]]: Read our guide if you haven&#039;t done much hardware before and need more fundamentals before diving in&lt;br /&gt;
* [[Swagbadge2021_GettingStarted|Getting started guide: Swagbadge]]: Your Swagbadge has arrived. What next?&lt;br /&gt;
* [[Swagbadge2021_SoftwareDev|SoftwareDev]]: Badge Software Development&lt;br /&gt;
* [[Swagbadge2021_MQTT|MQTT]]: Talking via MQTT&lt;br /&gt;
* [[Swagbadge2021_SoftwareDev|SoftwareDev]]: Badge Software Development&lt;br /&gt;
* [[SwagBadge2021 FAQ]]: Frequently Asked Questions&lt;br /&gt;
&lt;br /&gt;
== Resources ==&lt;br /&gt;
* [https://github.com/CCHS-Melbourne/Swag-Badge GitHub repository: #swagbadge hardware]&lt;br /&gt;
* [https://github.com/geekscape/aiko_engine_mp GitHub repository: Aiko Engine for microPython]: Not yet updated for #swagbadge&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Announcements ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Today (2020-10-04), we are publicly announcing the [https://lca2021.linux.org.au LCA2021] #swagbadge project&#039;&#039;&#039; and beginning the process of opening up our hardware and software development processes.  The next couple of weeks will be a bit of a spectator sport whilst we put in place mechanisms for technical collaboration and contributions.  We warmly welcome you to join in, get an early start on LCA2021 and enjoy the ride !  &#039;&#039;&#039;We&#039;ll be listening for questions and feedback sent to [https://twitter.com/swagbadge2021 Twitter @swagbadge]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Note: Whilst this project is supported by [https://lca2021.linux.org.au LCA2021], the OHMC team are not an official part of the LCA2021 organizing committee.  Of course, we&#039;ll be in close communication with them.  Also, this project will be covered by a [https://lca2021.linux.org.au/attend/code-of-conduct Code Of Conduct] (perhaps with some hardware hacking caveats).  The OHMC team supports and encourages inclusion and diversity in hardware / software hacking, please help us do better !&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Swag badge render 2020-09-30.jpg|360px|LCA2021 swag badge 3D render 2020-09-30]]  Recent 3D render 2020-09-30&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== LCA2021 #swagbadge announcement ===&lt;br /&gt;
&lt;br /&gt;
A limited number of &#039;&#039;&#039;LCA2021 Swag Badge&#039;&#039;&#039; electronic badges will be produced for the [https://lca2021.linux.org.au on-line LCA2021] conference, which will be distributed to conference attendees.  The LCA2021 Swag Badge is being specially developed and tailored for the conference.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;Note 0: This is just our current understanding of how the LCA2021 #swagbadge will be made available ... and is subject to change by LCA2021 organizing committee&#039;&#039;&lt;br /&gt;
* &#039;&#039;Note 1: The #swagbadge will be only available to Australian participants, due to the cost and delay of shipping internationally&#039;&#039;&lt;br /&gt;
* &#039;&#039;Note 2: If you are outside of Australia or miss out on a #swagbadge, then you might want to seriously consider acquiring a [[Swagbadge2021_Dagbadge|Dagbadge]]&#039;&#039;&lt;br /&gt;
* &#039;&#039;Note 3: The Open Hardware Miniconf is ON! [https://linux.conf.au/programme/miniconfs/open-hardware/ Submit your talk proposals today]. Deadline is Dec 18th.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
No ordinary conference badge, this one is full of extensible, open hardware, ready to be loaded up with whatever software and custom hardware add-ons takes your fancy !&lt;br /&gt;
&lt;br /&gt;
The Open Hardware Mini-Conference (OHMC) team are putting together a badge that will be:&lt;br /&gt;
&lt;br /&gt;
* Approachable for newcomers, e.g runs Python and doesn&#039;t require any special IDE (for embedded device development)&lt;br /&gt;
* Custom-designed, super slick PCB&lt;br /&gt;
* Powered by an ESP32 which gives you Wi-Fi and Bluetooth connectivity&lt;br /&gt;
* Not one, but two delightful OLED screens &lt;br /&gt;
* ... which double as pressable buttons&lt;br /&gt;
* Ready for development with the latest [http://micropython.org microPython] installed&lt;br /&gt;
* Supported by an open-sourced embedded network framework, the [https://github.com/geekscape/aiko_engine_mp Aiko Engine for microPython]&lt;br /&gt;
* With a number of [[Swagbadge2021_SAO|SAO connectors]] so you can extend and add on your own hardware components&lt;br /&gt;
&lt;br /&gt;
We aim to post the #swagbadges prior to Christmas so they will be available before [https://lca2021.linux.org.au on-line LCA2021] begins.&lt;br /&gt;
&lt;br /&gt;
But wait, there&#039;s more !  In the spirit of LCA, we want the capabilities of the badge to be truly open.  We&#039;ll be following up with more information about how you can join in to build out ideas for doing wonderful, magnificent, incredible... stuff ... &#039;&#039;&#039;&amp;lt;your idea here&amp;gt;&#039;&#039;&#039; ... using the [[Swagbadge2021_SAO|SAO connectors]]. &lt;br /&gt;
&lt;br /&gt;
Follow along and join in with the OHMC team as we prepare, plan, design and build your badges.  We&#039;ll be posting regular updates here on this Wiki.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Swag badge mechanical 2020-09-30.jpg|360px|LCA2021 swag badge mechanical layout 2020-09-30]]  Mechanical layout 2020-09-30&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Swagbadge2021 Backstory]]&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1287</id>
		<title>Swagbadge2021 GettingStarted</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Swagbadge2021_GettingStarted&amp;diff=1287"/>
		<updated>2021-01-15T05:27:31Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Getting started with the Swagbadge =&lt;br /&gt;
&lt;br /&gt;
== Support ==&lt;br /&gt;
* The [https://spectrum.chat/lca2021-swagbadge Swag Badge Spectrum chat] is a place where the badge team hangs out, ready to answer your questions.&lt;br /&gt;
&lt;br /&gt;
== My package arrived in the mail, first steps. ==&lt;br /&gt;
* Your package should contain your badge, and some other goodies! &lt;br /&gt;
** [[File:swagbadgepackage.jpg|400px|alt=Image showing the contents of the swagbag package]]&lt;br /&gt;
** Badge&lt;br /&gt;
** SAO headers (x 4)&lt;br /&gt;
** SAO proto boards (x 2)&lt;br /&gt;
** SAO tux board&lt;br /&gt;
** Lanyard&lt;br /&gt;
** Stickers&lt;br /&gt;
** Instructions&lt;br /&gt;
* Take off the protective cases to reveal the screens.&lt;br /&gt;
* Powering it up&lt;br /&gt;
** Insert a micro USB cable into the badge and connect the other end to a USB port on your computer or USB power source.&lt;br /&gt;
** A green light should glow on the rear of the board, and a title appear across the two screens.&lt;br /&gt;
* Turning it on and off again&lt;br /&gt;
** Plugging/unplugging it is fine. Usually the badge isn&#039;t running anything intensely enough that just unpowering it would cause a problem.&lt;br /&gt;
* On bootup, you should see:&lt;br /&gt;
** The OLED screens will display &amp;quot;Aiko&amp;quot; and a version number as a title&lt;br /&gt;
** It will also display something else to tell you to set up your wifi.&lt;br /&gt;
&lt;br /&gt;
== Getting it on your network ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Safety precautions we have provided&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* When using any hardware ordered off the internet, you can&#039;t be quite certain what software might be present on it. Before shipping these badges to you, we reflashed a fresh copy of MicroPython onto the Lolin32.&lt;br /&gt;
* The framework running on the badge is Aiko, which is open source.&lt;br /&gt;
* The software on the badge is available on the CCHS repository, also all open source.&lt;br /&gt;
* The badges are designed to communicate over MQTT - a lightweight standard for messaging on IoT devices, but we are aware of privacy considerations: you don&#039;t want anybody able to control your badge from afar. The swagbadge protocol provides support for encrypted messages.&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - wireless ===&lt;br /&gt;
&lt;br /&gt;
* The first time you boot your device, it won&#039;t know how to talk to your network. If it can&#039;t detect a pre-existing set of network credentials, or connect to anything it knows about, it will establish a temporary access point and prompt you to navigate to it to enter your wifi details.&lt;br /&gt;
* &#039;&#039;Note: Your device can only talk to a 2.4GHz network: it is not compatible with 5GHz WiFi.&#039;&#039;&lt;br /&gt;
* The screens on your badge will say: &amp;lt;code&amp;gt;Configure WiFi: aiko1234a12341234. Try http://192.168.4.1&amp;lt;/code&amp;gt;&lt;br /&gt;
* Use your phone or computer to connect to the wifi network on the badge. Its name starts with &amp;lt;code&amp;gt;aiko&amp;lt;/code&amp;gt; followed by some numbers/letters.&lt;br /&gt;
* Once you&#039;re connected to the badge, open a web browser to the IP address on the screens. Something like &amp;lt;code&amp;gt;http://192.168.4.1&amp;lt;/code&amp;gt;&lt;br /&gt;
* You&#039;ll be prompted to enter your wifi SSID and wifi password.&lt;br /&gt;
* Once you&#039;ve saved that, the badge will restart using the credentials you&#039;ve provided and it will shut down its wifi access point.&lt;br /&gt;
&lt;br /&gt;
Note: If you are using an Android device to link the badge to your WiFi, it will pop up a dialog to say you are switching to a network that doesn&#039;t have Internet access and ask if you want to switch back. Select &amp;quot;Keep&amp;quot; to stay on the badge&#039;s temporary access point.&lt;br /&gt;
&lt;br /&gt;
=== Getting the device on your wifi - commandline with mpfshell ===&lt;br /&gt;
&lt;br /&gt;
* If setting up via the wifi AP (access point) doesn&#039;t work, you can put a configuration file onto the badge.&lt;br /&gt;
* You&#039;ll need to start by getting [[Swagbadge2021_UpdatingSoftware|a copy of the aiko firmware, and installing mpfshell]]&lt;br /&gt;
* &#039;&#039;Note: Your device can only talk to a 2.4GHz network: it is not compatible with 5GHz.&#039;&#039;&lt;br /&gt;
* Edit aiko_engine_mp/configuration/net.py and insert the details of your SSID and password.&lt;br /&gt;
* use mpfshell: &amp;lt;code&amp;gt;mpfshell -o COM3&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;put configuration/net.py configuration/net.py&amp;lt;/code&amp;gt;&lt;br /&gt;
* fire up repl to view the console log &lt;br /&gt;
* You can now restart your device&lt;br /&gt;
* On bootup it should now talk to your network and you can see it on the console log.&lt;br /&gt;
&lt;br /&gt;
On bootup you should now see...&lt;br /&gt;
&lt;br /&gt;
= Running pre-installed applications =&lt;br /&gt;
&lt;br /&gt;
== Aiko&#039;s minimal Swagbadge application ==&lt;br /&gt;
At the moment the badge by default a basic &amp;quot;Swagbadge&amp;quot; application within the Aiko framework. This application&lt;br /&gt;
* has a thread to keep wifi running, &lt;br /&gt;
* has a thread to stay connected to (our Australian, private) mqtt server&lt;br /&gt;
* has a thread to display a rotating header across the two oleds.&lt;br /&gt;
&lt;br /&gt;
You can now talk to your badge [[Swagbadge2021_MQTT|using MQTT messages]].&lt;br /&gt;
&lt;br /&gt;
== Running other applications ==&lt;br /&gt;
At the moment, &amp;quot;swagbadge&amp;quot; is the only application that&#039;s for use with the badge. &lt;br /&gt;
&lt;br /&gt;
There are [https://github.com/geekscape/aiko_engine_mp/tree/master/applications other applications] in the repo which are for other places the Aiko framework has been used.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve written an application of your own and want to run that by default on badge startup, &lt;br /&gt;
# edit your local copy of configuration/main.py and change the value of the &amp;quot;application&amp;quot; to point to your new application.&lt;br /&gt;
# using mpfshell, &#039;put&#039; configuration/main.py and applications/your_application.py onto the badge&lt;br /&gt;
# Restart the badge&lt;br /&gt;
&lt;br /&gt;
== Running example code ==&lt;br /&gt;
There is [https://github.com/geekscape/aiko_engine_mp/tree/master/examples example code] which has a number of examples in it, including a snake game and a demo of how to use various badge functions.&lt;br /&gt;
&lt;br /&gt;
# From your commandline on your computer, use mpfshell to put whatever example code you want onto the badge.&lt;br /&gt;
# To run example code, you can use the &amp;quot;emergency stop&amp;quot; function to halt any other applications and put you in the repl.&lt;br /&gt;
## Touch both of the bottom spots on the sliders&lt;br /&gt;
## Reboot the badge&lt;br /&gt;
# Now at the repl prompt, type (replace the name of the module as appropriate for the code you want to run): &lt;br /&gt;
 &amp;lt;nowiki&amp;gt;use examples.game_snake as eg&lt;br /&gt;
from examples.game_snake import run&lt;br /&gt;
run()&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use ctrl-c to halt operation and return to the repl prompt.&lt;br /&gt;
&lt;br /&gt;
= Hardware pinout =&lt;br /&gt;
&lt;br /&gt;
You can get the schematic and pin mapping on this page: https://github.com/CCHS-Melbourne/Swag-Badge/blob/master/swag-badge-schematic.pdf&lt;br /&gt;
&lt;br /&gt;
= Extensions: Adding a SAO =&lt;br /&gt;
* provided by others&lt;br /&gt;
* build your own (linky here to our docs)&lt;br /&gt;
&lt;br /&gt;
= Extensions: Updating the software framework =&lt;br /&gt;
&lt;br /&gt;
Between when we ship the board and when it arrives, there might be some changes to the software framework (Aiko). Here&#039;s how to update it. Or perhaps you&#039;re interested in writing your own applications? &lt;br /&gt;
&lt;br /&gt;
* [[Swagbadge2021_UpdatingSoftware|Updating the Software]]&lt;br /&gt;
* [[Swagbadge2021_SoftwareDev|Writing your own badge programs]]&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=SwagBadge2021_FAQ&amp;diff=1286</id>
		<title>SwagBadge2021 FAQ</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=SwagBadge2021_FAQ&amp;diff=1286"/>
		<updated>2021-01-15T00:59:43Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* #swagbadge for LCA2021: Frequently Asked Questions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== #swagbadge for [https://lca2021.linux.org.au LCA2021]: Frequently Asked Questions ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;* Q: I&#039;m outside of Australia, how can I acquire #swagbadge hardware?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A: Right now, even the OHMC team doesn&#039;t have a #swagbadge, because the project development is still in progress.  However, we&#039;ve deliberately chosen readily available parts, i.e ESP32 Lolin32, 0.96&amp;quot; OLED screens and buttons, so that it is inexpensive and easy for anyone to acquire parts for participating in the development process along with us.  This also means that for those people we can&#039;t ship to, due to cost and time constraints, there is still an option for you to not miss out.  We will be providing a [https://en.wikipedia.org/wiki/Bill_of_materials BoM] soon that includes links for on-line purchasing of the parts.  This D.I.Y option is known as the #dagbadge !&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;* Q: What powers the badge? Can I run it off a battery?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You can plug a micro USB cable into the badge to provide power. We haven&#039;t provided one in the kits on the basis that everyone probably has plenty lying around at home already, and if not, they&#039;re easy and cheap to get hold of.&lt;br /&gt;
&lt;br /&gt;
It is possible to power the badge using a battery: the LOLIN32 has a JST header where a small 1S LiPo can be plugged in, but you&#039;ll need to provide the battery (and connect it to the badge) yourself. (Places like [https://hobbyking.com/en_us Hobby King] sell them, but the shipping isn&#039;t cheap.)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;* Q: Who is the team behind the Swagbadge?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The core team this year for OHMC is:&lt;br /&gt;
* [https://twitter.com/jonoxer Jon Oxer]&lt;br /&gt;
* [https://twitter.com/geekscape Andy Gelme]&lt;br /&gt;
* Andrew Nielsen&lt;br /&gt;
* [https://twitter.com/mage0r John Spencer]&lt;br /&gt;
* [https://twitter.com/nye_nicola Nicola Nye]&lt;br /&gt;
with help in all sorts of ways from many other individuals.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;* Q: I need more help!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Head over to https://spectrum.chat/lca2021-swagbadge .&lt;br /&gt;
All sorts of helpful and knowledgeable folk hang out there.&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=OHMC2019_Software_instructions&amp;diff=967</id>
		<title>OHMC2019 Software instructions</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=OHMC2019_Software_instructions&amp;diff=967"/>
		<updated>2019-01-24T04:14:16Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Neopixels */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
From a software perspective, the DonkeyCar (Raspberry Pi) is self-contained ... driving, data acquisition (for training) and ultimately self-driving are all performed with on-board software.  The provided micro-SD card already has all the required software pre-installed, as well as two pre-training A.I / Machine Learning models.  The DonkeyCar software includes a web-server that provides a web interface that works on both desktop and mobile web browsers (great for driving).&lt;br /&gt;
&lt;br /&gt;
Your laptop will be required to perform training of the Neural Network ... using the data acquired on the DonkeyCar.  This means that Python software will need to be installed, e.g TensorFlow (Machine Learning framework).&lt;br /&gt;
&lt;br /&gt;
== Software installation: Laptop / Desktop ==&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/install_software Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
* apt-get install -y virtualenv  # Note: You may be using a different software installer&lt;br /&gt;
* mkvirtualenv donkeycar -p python3&lt;br /&gt;
* pip install tensorflow==1.8.0  # Note: Probably requires Python 3.5 or 3.6.  People are having problems with Python 3.7&lt;br /&gt;
(if you get errors, you can try (re-) installing pip: python -m pip install --upgrade pip )&lt;br /&gt;
&lt;br /&gt;
On debian, if virtualenv isn&#039;t there, try this instead&lt;br /&gt;
* virtualenv donkeycar -p python3&lt;br /&gt;
* cd donkeycar&lt;br /&gt;
* export PATH=`pwd`/bin:$PATH&lt;br /&gt;
* pip install tensorflow==1.8.0&lt;br /&gt;
&lt;br /&gt;
Then proceed:&lt;br /&gt;
&lt;br /&gt;
* git clone https://github.com/autorope/donkeycar&lt;br /&gt;
* pip install -e ./donkeycar&lt;br /&gt;
&lt;br /&gt;
Note: You can manually install Python 3.6 as follows, but then you can&#039;t use mkvirtualenv ...&lt;br /&gt;
&lt;br /&gt;
* yum install python36&lt;br /&gt;
* python3.6 -m venv ~/virtualenvs/donkeycar&lt;br /&gt;
* source ~/virtualenvs/donkeycar/bin/activate&lt;br /&gt;
&lt;br /&gt;
== Software installation: Raspberry Pi ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Your DonkeyCar (Raspberry Pi) is already pre-installed.  This section is for reference only.&lt;br /&gt;
&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/install_software/#get-the-raspberry-pi-working Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
* sysctl -w net.ipv6.conf.all.disable_ipv6=1     # Reconnect via ssh afterwards&lt;br /&gt;
* sysctl -w net.ipv6.conf.default.disable_ipv6=1&lt;br /&gt;
&lt;br /&gt;
* apt-get update&lt;br /&gt;
* apt-get upgrade&lt;br /&gt;
* apt-get install -y vim git mosquitto-clients&lt;br /&gt;
* apt-get install -y virtualenv build-essential python3-dev gfortran libhdf5-dev libatlas-base-dev libopenjp2-7-dev libtiff5&lt;br /&gt;
&lt;br /&gt;
* apt-get install -y i2c-tools&lt;br /&gt;
* i2cdetect -y 1&lt;br /&gt;
         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f&lt;br /&gt;
    00:          -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    70: 70 -- -- -- -- -- -- --&lt;br /&gt;
&lt;br /&gt;
* mv env env.donkeycar&lt;br /&gt;
* virtualenv env -p python3&lt;br /&gt;
* pip install tensorflow==1.8.0&lt;br /&gt;
* pip install adafruit-pca9685&lt;br /&gt;
* pip install picamera&lt;br /&gt;
&lt;br /&gt;
== Finding your car on the network ==&lt;br /&gt;
&lt;br /&gt;
Your DonkeyCar (Raspberry Pi) has been pre-configured to connect to the LCA2019 network.  But, which IP address ?&lt;br /&gt;
&lt;br /&gt;
Every car has a unique hostname, from &#039;&#039;ohmc_01&#039;&#039; to &#039;&#039;ohmc_32&#039;&#039;.  The micro-SD card adapter is labeled with your car name.&lt;br /&gt;
&lt;br /&gt;
However, that still isn&#039;t enough to find your car.&lt;br /&gt;
&lt;br /&gt;
So, there is a &#039;&#039;cron&#039;&#039; job that every minute sends an MQTT message to &#039;&#039;test.mosquitto.org&#039;&#039; with your car&#039;s name, IP address and a timestamp.&lt;br /&gt;
&lt;br /&gt;
Install an MQTT client, as follows ...&lt;br /&gt;
&lt;br /&gt;
* apt-get install mosquitto-clients&lt;br /&gt;
&lt;br /&gt;
Use the following command to read the MQTT messages ...&lt;br /&gt;
&lt;br /&gt;
* mosquitto_sub -h test.mosquitto.org -t &#039;ohmc/#&#039; -v&lt;br /&gt;
&lt;br /&gt;
  ohmc/ohmc_01 10.193.2.69 Mon 11 Jun 07:08:01 UTC 2018&lt;br /&gt;
&lt;br /&gt;
== Driving the car manually ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Caution: Put your car &amp;quot;on blocks&amp;quot; (wheels off the ground) the first time you try driving it&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/get_driving Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
IP_ADDRESS=xxx.xxx.xxx.xxx  # Found as above&lt;br /&gt;
&lt;br /&gt;
* ssh pi@$IP_ADDRESS  # Note: Raspberry Pi default username: &#039;&#039;pi&#039;&#039; and password: &#039;&#039;raspberry&#039;&#039;&lt;br /&gt;
* cd ohmc_car&lt;br /&gt;
* python manage.py drive&lt;br /&gt;
&lt;br /&gt;
  loading config file: /home/pi/play/roba_car/config.py&lt;br /&gt;
  config loaded&lt;br /&gt;
  PiCamera loaded.. .warming camera&lt;br /&gt;
  Starting Donkey Server...&lt;br /&gt;
  You can now go to http://xxx.xxx.xxx.xxx:8887 to drive your car.&lt;br /&gt;
&lt;br /&gt;
With a desktop web browser, the user interface provides a virtual joystick (right-hand frame) that you can use to drive the car ... altering the steering and throttle values.&lt;br /&gt;
&lt;br /&gt;
The mobile web browser, the user interface allows you to drive by tilting the phone left-right for steering and forwards-backwards for throttle.  For safety, you must press the [Start Vehicle] / [Stop Vehicle] toggle button to enable control.&lt;br /&gt;
&lt;br /&gt;
== rPi reboots and Auto-starting donkeycar without logging in ==&lt;br /&gt;
&lt;br /&gt;
If your rPi reboots when you&#039;re driving, check the following things:&lt;br /&gt;
# did you swap the servo wires between steering and power. Turn the ESC off, unplug one servo wire, turn the ESC back on (little toggle switch), and test steering. Make sure that steering does not activate the wheel motors.  &lt;br /&gt;
# is your battery low? are you accelerating too quickly?  &lt;br /&gt;
Because the battery has a high internal resistance, if you demand a lot of power too quickly, the voltage on the battery drops enough that the rPi gets below its critical voltage (when you add the voltage drop from the voltage converter), and the rPi reboots.&lt;br /&gt;
&lt;br /&gt;
To restart donkey server automatically, do the following:   &lt;br /&gt;
* Add this to /etc/rc.local:   &lt;br /&gt;
su - pi -c &#039;cd ~/ohmc_car; python manage.py drive &amp;amp;&amp;gt;/tmp/out&#039; &amp;amp;   &lt;br /&gt;
* move &#039;source ~/env/bin/activate&#039; from ~/.bashrc to ~/.profile&lt;br /&gt;
&lt;br /&gt;
== Steering and throttle calibration ==&lt;br /&gt;
&lt;br /&gt;
To save time at the workshop, you won&#039;t need to calibrate your car&#039;s steering and/or throttle.&lt;br /&gt;
&lt;br /&gt;
However, you may get better results and can perform calibration when you have time ... [http://docs.donkeycar.com/guide/calibrate by following the DonkeyCar instructions]&lt;br /&gt;
&lt;br /&gt;
== Data acquisition for the Neural Network ==&lt;br /&gt;
&lt;br /&gt;
Once you are driving your car confidently around a track ... it is time to acquire training data for the Neural Network.  DonkeyCar operates at 10 frames per second, capturing a 160x120 image, along with steering angle and throttle value.  This is all stored in the &#039;&#039;$HOME/ohmc_car/tub/&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
Before training, it is a good idea to clean out previous data.  Don&#039;t just remove all the files in the &#039;&#039;tub/&#039;&#039; directory !  The &#039;&#039;tub/meta.json&#039;&#039; file is important.&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/train_autopilot Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
Perform the same commands as for manual driving ...&lt;br /&gt;
&lt;br /&gt;
* ssh pi@$IP_ADDRESS&lt;br /&gt;
* cd ohmc_car&lt;br /&gt;
* python manage.py drive&lt;br /&gt;
&lt;br /&gt;
Then via the web browser press the [Start Recording] button ... drive the car around a track ... then press the [Stop Recording] button.&lt;br /&gt;
&lt;br /&gt;
It is recommended that you collect between 5K and 20K frames.  At 10 frames per second, that is between 500 and 2,000 seconds of driving.  Make sure that you drive clockwise and anti-clockwise.&lt;br /&gt;
&lt;br /&gt;
You will need to type this command just once on your DonkeyCar (Raspberry Pi)to provide a directory on your laptop for your training data ...&lt;br /&gt;
&lt;br /&gt;
* rsync -av pi@&amp;lt;car_ip&amp;gt;:ohmc_car .&lt;br /&gt;
&lt;br /&gt;
When finished acquisition, then transfer the data from the DonkeyCar (Raspberry Pi) to your laptop / desktop for training the Neural Network.&lt;br /&gt;
&lt;br /&gt;
* rsync -av pi@&amp;lt;car_ip&amp;gt;:ohmc_car/tub ohmc_car/tub_$DATE&lt;br /&gt;
&lt;br /&gt;
== Training the Neural Network ==&lt;br /&gt;
&lt;br /&gt;
Once training data has been copied to your laptop / desktop, you can begin training the Neural Network.&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/train_autopilot Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
Run these commands on your laptop / desktop to train the Neural Network ...&lt;br /&gt;
&lt;br /&gt;
* workon donkeycar  # For those who have set-up a virtualenv&lt;br /&gt;
* cd ohmc_car&lt;br /&gt;
* python manage.py train --tub $HOME/ohmc_car/tub_$DATE --model ./models/model_$DATE.hdf5&lt;br /&gt;
&lt;br /&gt;
  using donkey version: 2.5.7 ...&lt;br /&gt;
  loading config file: /Users/andyg/play/ai/roba_car/config.py&lt;br /&gt;
  config loaded&lt;br /&gt;
  tub_names ./tub_2019-01-15c&lt;br /&gt;
  train: 5740, validation: 1436&lt;br /&gt;
  steps_per_epoch 44&lt;br /&gt;
  Epoch 1/100&lt;br /&gt;
  2019-01-21 13:08:49.507048: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA&lt;br /&gt;
  43/44 [============================&amp;gt;.] - ETA: 0s - loss: 58.5130 - angle_out_loss: 30.3421 - throttle_out_loss: 86.6839      &lt;br /&gt;
  Epoch 00001: val_loss improved from inf to 0.19699, saving model to ./models/roba0_2019-01-16c.hdf5&lt;br /&gt;
  44/44 [==============================] - 38s 874ms/step - loss: 57.1887 - angle_out_loss: 29.6601 - throttle_out_loss: 84.7172 - val_loss: 0.1970 - val_angle_out_loss: 0.3230 - val_throttle_out_loss: 0.0710&lt;br /&gt;
&lt;br /&gt;
On a modern laptop, each epoch will take around 30 seconds to complete.  For up-to 100 epochs.  Typically, you can expect around 20 to 40 epochs before the Neural Network stop learning.  That is around 10 to 20 minutes of training time.&lt;br /&gt;
&lt;br /&gt;
The training command creates the Neural Network weights that represent what your DonkeyCar has &amp;quot;learned&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
When training has completed, copy the trained model back to your DonkeyCar (Raspberry Pi)&lt;br /&gt;
&lt;br /&gt;
* scp $USERNAME@$HOSTNAME:ohmc_car/models/model_$DATE.hdf5 models&lt;br /&gt;
&lt;br /&gt;
== Self-driving ... the ultimate goal ==&lt;br /&gt;
&lt;br /&gt;
Once your trained model has been copied back onto the DonkeyCar (Raspberry Pi), your car can be self-driven as follow ...&lt;br /&gt;
&lt;br /&gt;
* python manage.py drive --model ~/ohmc_car/models/models/model_$DATE.hdf5&lt;br /&gt;
&lt;br /&gt;
This works similar to the manual driving mode with the addition of a trained model that can either ...&lt;br /&gt;
&lt;br /&gt;
1) User: Manual control of both steering and throttle&lt;br /&gt;
&lt;br /&gt;
2) Local Angle: Automatically control the steering angle&lt;br /&gt;
&lt;br /&gt;
3) Local pilot: Automatically control both the steering angle and throttle amount&lt;br /&gt;
&lt;br /&gt;
The web browser provides a drop-down menu to select between these options.&lt;br /&gt;
&lt;br /&gt;
It is recommended to just start with Local Angle ... and control the throttle manually with the &amp;quot;i&amp;quot; key (faster) and &amp;quot;k&amp;quot; key (slower).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Neopixels ==&lt;br /&gt;
&lt;br /&gt;
On the car, do this: pip install rpi_ws281x adafruit-circuitpython-neopixel  --trusted-host pypi.org --trusted-host files.pythonhosted.org --trusted-host www.piwheels.org&lt;br /&gt;
&lt;br /&gt;
The details come from here: https://learn.adafruit.com/neopixels-on-raspberry-pi/overview&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(env) pi@ohmc_24:~/ohmc_car$ diff -u manage.py.orig manage.py&lt;br /&gt;
--- manage.py.orig	2018-06-11 08:14:34.079999106 +0000&lt;br /&gt;
+++ manage.py	2018-06-11 08:37:05.959999560 +0000&lt;br /&gt;
@@ -122,6 +122,9 @@&lt;br /&gt;
     tub = TubWriter(path=cfg.TUB_PATH, inputs=inputs, types=types)&lt;br /&gt;
     V.add(tub, inputs=inputs, run_condition=&#039;recording&#039;)&lt;br /&gt;
 &lt;br /&gt;
+    pixels[0] = (32, 64, 128)&lt;br /&gt;
+    pixels[1] = (0, 255, 0)&lt;br /&gt;
+&lt;br /&gt;
     # run the vehicle&lt;br /&gt;
     V.start(rate_hz=cfg.DRIVE_LOOP_HZ,&lt;br /&gt;
             max_loop_count=cfg.MAX_LOOPS)&lt;br /&gt;
@@ -169,6 +172,13 @@&lt;br /&gt;
     cfg = dk.load_config()&lt;br /&gt;
 &lt;br /&gt;
     if args[&#039;drive&#039;]:&lt;br /&gt;
+        # Neopixels&lt;br /&gt;
+        # https://learn.adafruit.com/neopixels-on-raspberry-pi/python-usage&lt;br /&gt;
+        import board&lt;br /&gt;
+        import neopixel&lt;br /&gt;
+        pixels = neopixel.NeoPixel(board.D18, 2)&lt;br /&gt;
+        pixels[0] = (0, 0, 0)&lt;br /&gt;
+        pixels[1] = (0, 64, 0)&lt;br /&gt;
         drive(cfg, model_path=args[&#039;--model&#039;], use_chaos=args[&#039;--chaos&#039;])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you need to run as root for neopixels to work:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo /home/pi/env/bin/python manage.py drive &lt;br /&gt;
--model=/home/pi/ohmc_car/models/large_track.hdf5&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Neopixels v2 ==&lt;br /&gt;
&lt;br /&gt;
* Get https://gist.github.com/marcmerlin/a3bba2231a3371266e595aa0e6028b77&lt;br /&gt;
* Save under /home/pi/ and /etc/rc.local&lt;br /&gt;
* Apply manage.py.diff to /home/pi/ohmc_car/manage.py&lt;br /&gt;
* Reboot and both the led server and the car software should start&lt;br /&gt;
* You can force an led pattern or color like so&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(env) pi@ohmc_24:~/ohmc_car$ echo -n rainbow &amp;gt; /tmp/leds&lt;br /&gt;
(env) pi@ohmc_24:~/ohmc_car$ echo -n b &amp;gt; /tmp/leds&lt;br /&gt;
(env) pi@ohmc_24:~/ohmc_car$ echo -n cylon &amp;gt; /tmp/leds&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Reboot and both the led server&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=OHMC2019_Software_instructions&amp;diff=966</id>
		<title>OHMC2019 Software instructions</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=OHMC2019_Software_instructions&amp;diff=966"/>
		<updated>2019-01-21T09:06:26Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: Added neopixel info&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
From a software perspective, the DonkeyCar (Raspberry Pi) is self-contained ... driving, data acquisition (for training) and ultimately self-driving are all performed with on-board software.  The provided micro-SD card already has all the required software pre-installed, as well as two pre-training A.I / Machine Learning models.  The DonkeyCar software includes a web-server that provides a web interface that works on both desktop and mobile web browsers (great for driving).&lt;br /&gt;
&lt;br /&gt;
Your laptop will be required to perform training of the Neural Network ... using the data acquired on the DonkeyCar.  This means that Python software will need to be installed, e.g TensorFlow (Machine Learning framework).&lt;br /&gt;
&lt;br /&gt;
== Software installation: Laptop / Desktop ==&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/install_software Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
* apt-get install -y virtualenv  # Note: You may be using a different software installer&lt;br /&gt;
* mkvirtualenv donkeycar -p python3&lt;br /&gt;
* pip install tensorflow==1.8.0  # Note: Probably requires Python 3.5 or 3.6.  People are having problems with Python 3.7&lt;br /&gt;
(if you get errors, you can try (re-) installing pip: python -m pip install --upgrade pip )&lt;br /&gt;
&lt;br /&gt;
On debian, if virtualenv isn&#039;t there, try this instead&lt;br /&gt;
* virtualenv donkeycar -p python3&lt;br /&gt;
* cd donkeycar&lt;br /&gt;
* export PATH=`pwd`/bin:$PATH&lt;br /&gt;
* pip install tensorflow==1.8.0&lt;br /&gt;
&lt;br /&gt;
Then proceed:&lt;br /&gt;
&lt;br /&gt;
* git clone https://github.com/autorope/donkeycar&lt;br /&gt;
* pip install -e ./donkeycar&lt;br /&gt;
&lt;br /&gt;
Note: You can manually install Python 3.6 as follows, but then you can&#039;t use mkvirtualenv ...&lt;br /&gt;
&lt;br /&gt;
* yum install python36&lt;br /&gt;
* python3.6 -m venv ~/virtualenvs/donkeycar&lt;br /&gt;
* source ~/virtualenvs/donkeycar/bin/activate&lt;br /&gt;
&lt;br /&gt;
== Software installation: Raspberry Pi ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Your DonkeyCar (Raspberry Pi) is already pre-installed.  This section is for reference only.&lt;br /&gt;
&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/install_software/#get-the-raspberry-pi-working Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
* sysctl -w net.ipv6.conf.all.disable_ipv6=1     # Reconnect via ssh afterwards&lt;br /&gt;
* sysctl -w net.ipv6.conf.default.disable_ipv6=1&lt;br /&gt;
&lt;br /&gt;
* apt-get update&lt;br /&gt;
* apt-get upgrade&lt;br /&gt;
* apt-get install -y vim git mosquitto-clients&lt;br /&gt;
* apt-get install -y virtualenv build-essential python3-dev gfortran libhdf5-dev libatlas-base-dev libopenjp2-7-dev libtiff5&lt;br /&gt;
&lt;br /&gt;
* apt-get install -y i2c-tools&lt;br /&gt;
* i2cdetect -y 1&lt;br /&gt;
         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f&lt;br /&gt;
    00:          -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    70: 70 -- -- -- -- -- -- --&lt;br /&gt;
&lt;br /&gt;
* mv env env.donkeycar&lt;br /&gt;
* virtualenv env -p python3&lt;br /&gt;
* pip install tensorflow==1.8.0&lt;br /&gt;
* pip install adafruit-pca9685&lt;br /&gt;
* pip install picamera&lt;br /&gt;
&lt;br /&gt;
== Finding your car on the network ==&lt;br /&gt;
&lt;br /&gt;
Your DonkeyCar (Raspberry Pi) has been pre-configured to connect to the LCA2019 network.  But, which IP address ?&lt;br /&gt;
&lt;br /&gt;
Every car has a unique hostname, from &#039;&#039;ohmc_01&#039;&#039; to &#039;&#039;ohmc_32&#039;&#039;.  The micro-SD card adapter is labeled with your car name.&lt;br /&gt;
&lt;br /&gt;
However, that still isn&#039;t enough to find your car.&lt;br /&gt;
&lt;br /&gt;
So, there is a &#039;&#039;cron&#039;&#039; job that every minute sends an MQTT message to &#039;&#039;test.mosquitto.org&#039;&#039; with your car&#039;s name, IP address and a timestamp.&lt;br /&gt;
&lt;br /&gt;
Install an MQTT client, as follows ...&lt;br /&gt;
&lt;br /&gt;
* apt-get install mosquitto-clients&lt;br /&gt;
&lt;br /&gt;
Use the following command to read the MQTT messages ...&lt;br /&gt;
&lt;br /&gt;
* mosquitto_sub -h test.mosquitto.org -t &#039;ohmc/#&#039; -v&lt;br /&gt;
&lt;br /&gt;
  ohmc/ohmc_01 10.193.2.69 Mon 11 Jun 07:08:01 UTC 2018&lt;br /&gt;
&lt;br /&gt;
== Driving the car manually ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Caution: Put your car &amp;quot;on blocks&amp;quot; (wheels off the ground) the first time you try driving it&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/get_driving Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
IP_ADDRESS=xxx.xxx.xxx.xxx  # Found as above&lt;br /&gt;
&lt;br /&gt;
* ssh pi@$IP_ADDRESS  # Note: Raspberry Pi default username: &#039;&#039;pi&#039;&#039; and password: &#039;&#039;raspberry&#039;&#039;&lt;br /&gt;
* cd ohmc_car&lt;br /&gt;
* python manage.py drive&lt;br /&gt;
&lt;br /&gt;
  loading config file: /home/pi/play/roba_car/config.py&lt;br /&gt;
  config loaded&lt;br /&gt;
  PiCamera loaded.. .warming camera&lt;br /&gt;
  Starting Donkey Server...&lt;br /&gt;
  You can now go to http://xxx.xxx.xxx.xxx:8887 to drive your car.&lt;br /&gt;
&lt;br /&gt;
With a desktop web browser, the user interface provides a virtual joystick (right-hand frame) that you can use to drive the car ... altering the steering and throttle values.&lt;br /&gt;
&lt;br /&gt;
The mobile web browser, the user interface allows you to drive by tilting the phone left-right for steering and forwards-backwards for throttle.  For safety, you must press the [Start Vehicle] / [Stop Vehicle] toggle button to enable control.&lt;br /&gt;
&lt;br /&gt;
== rPi reboots and Auto-starting donkeycar without logging in ==&lt;br /&gt;
&lt;br /&gt;
If your rPi reboots when you&#039;re driving, check the following things:&lt;br /&gt;
# did you swap the servo wires between steering and power. Turn the ESC off, unplug one servo wire, turn the ESC back on (little toggle switch), and test steering. Make sure that steering does not activate the wheel motors.  &lt;br /&gt;
# is your battery low? are you accelerating too quickly?  &lt;br /&gt;
Because the battery has a high internal resistance, if you demand a lot of power too quickly, the voltage on the battery drops enough that the rPi gets below its critical voltage (when you add the voltage drop from the voltage converter), and the rPi reboots.&lt;br /&gt;
&lt;br /&gt;
To restart donkey server automatically, do the following:   &lt;br /&gt;
* Add this to /etc/rc.local:   &lt;br /&gt;
su - pi -c &#039;cd ~/ohmc_car; python manage.py drive &amp;amp;&amp;gt;/tmp/out&#039; &amp;amp;   &lt;br /&gt;
* move &#039;source ~/env/bin/activate&#039; from ~/.bashrc to ~/.profile&lt;br /&gt;
&lt;br /&gt;
== Steering and throttle calibration ==&lt;br /&gt;
&lt;br /&gt;
To save time at the workshop, you won&#039;t need to calibrate your car&#039;s steering and/or throttle.&lt;br /&gt;
&lt;br /&gt;
However, you may get better results and can perform calibration when you have time ... [http://docs.donkeycar.com/guide/calibrate by following the DonkeyCar instructions]&lt;br /&gt;
&lt;br /&gt;
== Data acquisition for the Neural Network ==&lt;br /&gt;
&lt;br /&gt;
Once you are driving your car confidently around a track ... it is time to acquire training data for the Neural Network.  DonkeyCar operates at 10 frames per second, capturing a 160x120 image, along with steering angle and throttle value.  This is all stored in the &#039;&#039;$HOME/ohmc_car/tub/&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
Before training, it is a good idea to clean out previous data.  Don&#039;t just remove all the files in the &#039;&#039;tub/&#039;&#039; directory !  The &#039;&#039;tub/meta.json&#039;&#039; file is important.&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/train_autopilot Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
Perform the same commands as for manual driving ...&lt;br /&gt;
&lt;br /&gt;
* ssh pi@$IP_ADDRESS&lt;br /&gt;
* cd ohmc_car&lt;br /&gt;
* python manage.py drive&lt;br /&gt;
&lt;br /&gt;
Then via the web browser press the [Start Recording] button ... drive the car around a track ... then press the [Stop Recording] button.&lt;br /&gt;
&lt;br /&gt;
It is recommended that you collect between 5K and 20K frames.  At 10 frames per second, that is between 500 and 2,000 seconds of driving.  Make sure that you drive clockwise and anti-clockwise.&lt;br /&gt;
&lt;br /&gt;
You will need to type this command just once on your DonkeyCar (Raspberry Pi)to provide a directory on your laptop for your training data ...&lt;br /&gt;
&lt;br /&gt;
* rsync -av pi@&amp;lt;car_ip&amp;gt;:ohmc_car .&lt;br /&gt;
&lt;br /&gt;
When finished acquisition, then transfer the data from the DonkeyCar (Raspberry Pi) to your laptop / desktop for training the Neural Network.&lt;br /&gt;
&lt;br /&gt;
* rsync -av pi@&amp;lt;car_ip&amp;gt;:ohmc_car/tub ohmc_car/tub_$DATE&lt;br /&gt;
&lt;br /&gt;
== Training the Neural Network ==&lt;br /&gt;
&lt;br /&gt;
Once training data has been copied to your laptop / desktop, you can begin training the Neural Network.&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/train_autopilot Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
Run these commands on your laptop / desktop to train the Neural Network ...&lt;br /&gt;
&lt;br /&gt;
* workon donkeycar  # For those who have set-up a virtualenv&lt;br /&gt;
* cd ohmc_car&lt;br /&gt;
* python manage.py train --tub $HOME/ohmc_car/tub_$DATE --model ./models/model_$DATE.hdf5&lt;br /&gt;
&lt;br /&gt;
  using donkey version: 2.5.7 ...&lt;br /&gt;
  loading config file: /Users/andyg/play/ai/roba_car/config.py&lt;br /&gt;
  config loaded&lt;br /&gt;
  tub_names ./tub_2019-01-15c&lt;br /&gt;
  train: 5740, validation: 1436&lt;br /&gt;
  steps_per_epoch 44&lt;br /&gt;
  Epoch 1/100&lt;br /&gt;
  2019-01-21 13:08:49.507048: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA&lt;br /&gt;
  43/44 [============================&amp;gt;.] - ETA: 0s - loss: 58.5130 - angle_out_loss: 30.3421 - throttle_out_loss: 86.6839      &lt;br /&gt;
  Epoch 00001: val_loss improved from inf to 0.19699, saving model to ./models/roba0_2019-01-16c.hdf5&lt;br /&gt;
  44/44 [==============================] - 38s 874ms/step - loss: 57.1887 - angle_out_loss: 29.6601 - throttle_out_loss: 84.7172 - val_loss: 0.1970 - val_angle_out_loss: 0.3230 - val_throttle_out_loss: 0.0710&lt;br /&gt;
&lt;br /&gt;
On a modern laptop, each epoch will take around 30 seconds to complete.  For up-to 100 epochs.  Typically, you can expect around 20 to 40 epochs before the Neural Network stop learning.  That is around 10 to 20 minutes of training time.&lt;br /&gt;
&lt;br /&gt;
The training command creates the Neural Network weights that represent what your DonkeyCar has &amp;quot;learned&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
When training has completed, copy the trained model back to your DonkeyCar (Raspberry Pi)&lt;br /&gt;
&lt;br /&gt;
* scp $USERNAME@$HOSTNAME:ohmc_car/models/model_$DATE.hdf5 models&lt;br /&gt;
&lt;br /&gt;
== Self-driving ... the ultimate goal ==&lt;br /&gt;
&lt;br /&gt;
Once your trained model has been copied back onto the DonkeyCar (Raspberry Pi), your car can be self-driven as follow ...&lt;br /&gt;
&lt;br /&gt;
* python manage.py drive --model ~/ohmc_car/models/models/model_$DATE.hdf5&lt;br /&gt;
&lt;br /&gt;
This works similar to the manual driving mode with the addition of a trained model that can either ...&lt;br /&gt;
&lt;br /&gt;
1) User: Manual control of both steering and throttle&lt;br /&gt;
&lt;br /&gt;
2) Local Angle: Automatically control the steering angle&lt;br /&gt;
&lt;br /&gt;
3) Local pilot: Automatically control both the steering angle and throttle amount&lt;br /&gt;
&lt;br /&gt;
The web browser provides a drop-down menu to select between these options.&lt;br /&gt;
&lt;br /&gt;
It is recommended to just start with Local Angle ... and control the throttle manually with the &amp;quot;i&amp;quot; key (faster) and &amp;quot;k&amp;quot; key (slower).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Neopixels ==&lt;br /&gt;
&lt;br /&gt;
On the car, do this: pip install rpi_ws281x adafruit-circuitpython-neopixel  --trusted-host pypi.org --trusted-host files.pythonhosted.org --trusted-host www.piwheels.org&lt;br /&gt;
&lt;br /&gt;
The details come from here: https://learn.adafruit.com/neopixels-on-raspberry-pi/overview&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(env) pi@ohmc_24:~/ohmc_car$ diff -u manage.py.orig manage.py&lt;br /&gt;
--- manage.py.orig	2018-06-11 08:14:34.079999106 +0000&lt;br /&gt;
+++ manage.py	2018-06-11 08:37:05.959999560 +0000&lt;br /&gt;
@@ -122,6 +122,9 @@&lt;br /&gt;
     tub = TubWriter(path=cfg.TUB_PATH, inputs=inputs, types=types)&lt;br /&gt;
     V.add(tub, inputs=inputs, run_condition=&#039;recording&#039;)&lt;br /&gt;
 &lt;br /&gt;
+    pixels[0] = (32, 64, 128)&lt;br /&gt;
+    pixels[1] = (0, 255, 0)&lt;br /&gt;
+&lt;br /&gt;
     # run the vehicle&lt;br /&gt;
     V.start(rate_hz=cfg.DRIVE_LOOP_HZ,&lt;br /&gt;
             max_loop_count=cfg.MAX_LOOPS)&lt;br /&gt;
@@ -169,6 +172,13 @@&lt;br /&gt;
     cfg = dk.load_config()&lt;br /&gt;
 &lt;br /&gt;
     if args[&#039;drive&#039;]:&lt;br /&gt;
+        # Neopixels&lt;br /&gt;
+        # https://learn.adafruit.com/neopixels-on-raspberry-pi/python-usage&lt;br /&gt;
+        import board&lt;br /&gt;
+        import neopixel&lt;br /&gt;
+        pixels = neopixel.NeoPixel(board.D18, 2)&lt;br /&gt;
+        pixels[0] = (0, 0, 0)&lt;br /&gt;
+        pixels[1] = (0, 64, 0)&lt;br /&gt;
         drive(cfg, model_path=args[&#039;--model&#039;], use_chaos=args[&#039;--chaos&#039;])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you need to run as root for neopixels to work:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo /home/pi/env/bin/python manage.py drive --model=/home/pi/ohmc_car/models/large_track.hdf5&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=OHMC2019_Software_instructions&amp;diff=965</id>
		<title>OHMC2019 Software instructions</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=OHMC2019_Software_instructions&amp;diff=965"/>
		<updated>2019-01-21T08:50:39Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: improve security of data retrieval from car&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
From a software perspective, the DonkeyCar (Raspberry Pi) is self-contained ... driving, data acquisition (for training) and ultimately self-driving are all performed with on-board software.  The provided micro-SD card already has all the required software pre-installed, as well as two pre-training A.I / Machine Learning models.  The DonkeyCar software includes a web-server that provides a web interface that works on both desktop and mobile web browsers (great for driving).&lt;br /&gt;
&lt;br /&gt;
Your laptop will be required to perform training of the Neural Network ... using the data acquired on the DonkeyCar.  This means that Python software will need to be installed, e.g TensorFlow (Machine Learning framework).&lt;br /&gt;
&lt;br /&gt;
== Software installation: Laptop / Desktop ==&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/install_software Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
* apt-get install -y virtualenv  # Note: You may be using a different software installer&lt;br /&gt;
* mkvirtualenv donkeycar -p python3&lt;br /&gt;
* pip install tensorflow==1.8.0  # Note: Probably requires Python 3.5 or 3.6.  People are having problems with Python 3.7&lt;br /&gt;
(if you get errors, you can try (re-) installing pip: python -m pip install --upgrade pip )&lt;br /&gt;
&lt;br /&gt;
On debian, if virtualenv isn&#039;t there, try this instead&lt;br /&gt;
* virtualenv donkeycar -p python3&lt;br /&gt;
* cd donkeycar&lt;br /&gt;
* export PATH=`pwd`/bin:$PATH&lt;br /&gt;
* pip install tensorflow==1.8.0&lt;br /&gt;
&lt;br /&gt;
Then proceed:&lt;br /&gt;
&lt;br /&gt;
* git clone https://github.com/autorope/donkeycar&lt;br /&gt;
* pip install -e ./donkeycar&lt;br /&gt;
&lt;br /&gt;
Note: You can manually install Python 3.6 as follows, but then you can&#039;t use mkvirtualenv ...&lt;br /&gt;
&lt;br /&gt;
* yum install python36&lt;br /&gt;
* python3.6 -m venv ~/virtualenvs/donkeycar&lt;br /&gt;
* source ~/virtualenvs/donkeycar/bin/activate&lt;br /&gt;
&lt;br /&gt;
== Software installation: Raspberry Pi ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Your DonkeyCar (Raspberry Pi) is already pre-installed.  This section is for reference only.&lt;br /&gt;
&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/install_software/#get-the-raspberry-pi-working Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
* sysctl -w net.ipv6.conf.all.disable_ipv6=1     # Reconnect via ssh afterwards&lt;br /&gt;
* sysctl -w net.ipv6.conf.default.disable_ipv6=1&lt;br /&gt;
&lt;br /&gt;
* apt-get update&lt;br /&gt;
* apt-get upgrade&lt;br /&gt;
* apt-get install -y vim git mosquitto-clients&lt;br /&gt;
* apt-get install -y virtualenv build-essential python3-dev gfortran libhdf5-dev libatlas-base-dev libopenjp2-7-dev libtiff5&lt;br /&gt;
&lt;br /&gt;
* apt-get install -y i2c-tools&lt;br /&gt;
* i2cdetect -y 1&lt;br /&gt;
         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f&lt;br /&gt;
    00:          -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    70: 70 -- -- -- -- -- -- --&lt;br /&gt;
&lt;br /&gt;
* mv env env.donkeycar&lt;br /&gt;
* virtualenv env -p python3&lt;br /&gt;
* pip install tensorflow==1.8.0&lt;br /&gt;
* pip install adafruit-pca9685&lt;br /&gt;
* pip install picamera&lt;br /&gt;
&lt;br /&gt;
== Finding your car on the network ==&lt;br /&gt;
&lt;br /&gt;
Your DonkeyCar (Raspberry Pi) has been pre-configured to connect to the LCA2019 network.  But, which IP address ?&lt;br /&gt;
&lt;br /&gt;
Every car has a unique hostname, from &#039;&#039;ohmc_01&#039;&#039; to &#039;&#039;ohmc_32&#039;&#039;.  The micro-SD card adapter is labeled with your car name.&lt;br /&gt;
&lt;br /&gt;
However, that still isn&#039;t enough to find your car.&lt;br /&gt;
&lt;br /&gt;
So, there is a &#039;&#039;cron&#039;&#039; job that every minute sends an MQTT message to &#039;&#039;test.mosquitto.org&#039;&#039; with your car&#039;s name, IP address and a timestamp.&lt;br /&gt;
&lt;br /&gt;
Install an MQTT client, as follows ...&lt;br /&gt;
&lt;br /&gt;
* apt-get install mosquitto-clients&lt;br /&gt;
&lt;br /&gt;
Use the following command to read the MQTT messages ...&lt;br /&gt;
&lt;br /&gt;
* mosquitto_sub -h test.mosquitto.org -t &#039;ohmc/#&#039; -v&lt;br /&gt;
&lt;br /&gt;
  ohmc/ohmc_01 10.193.2.69 Mon 11 Jun 07:08:01 UTC 2018&lt;br /&gt;
&lt;br /&gt;
== Driving the car manually ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Caution: Put your car &amp;quot;on blocks&amp;quot; (wheels off the ground) the first time you try driving it&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/get_driving Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
IP_ADDRESS=xxx.xxx.xxx.xxx  # Found as above&lt;br /&gt;
&lt;br /&gt;
* ssh pi@$IP_ADDRESS  # Note: Raspberry Pi default username: &#039;&#039;pi&#039;&#039; and password: &#039;&#039;raspberry&#039;&#039;&lt;br /&gt;
* cd ohmc_car&lt;br /&gt;
* python manage.py drive&lt;br /&gt;
&lt;br /&gt;
  loading config file: /home/pi/play/roba_car/config.py&lt;br /&gt;
  config loaded&lt;br /&gt;
  PiCamera loaded.. .warming camera&lt;br /&gt;
  Starting Donkey Server...&lt;br /&gt;
  You can now go to http://xxx.xxx.xxx.xxx:8887 to drive your car.&lt;br /&gt;
&lt;br /&gt;
With a desktop web browser, the user interface provides a virtual joystick (right-hand frame) that you can use to drive the car ... altering the steering and throttle values.&lt;br /&gt;
&lt;br /&gt;
The mobile web browser, the user interface allows you to drive by tilting the phone left-right for steering and forwards-backwards for throttle.  For safety, you must press the [Start Vehicle] / [Stop Vehicle] toggle button to enable control.&lt;br /&gt;
&lt;br /&gt;
== rPi reboots and Auto-starting donkeycar without logging in ==&lt;br /&gt;
&lt;br /&gt;
If your rPi reboots when you&#039;re driving, check the following things:&lt;br /&gt;
# did you swap the servo wires between steering and power. Turn the ESC off, unplug one servo wire, turn the ESC back on (little toggle switch), and test steering. Make sure that steering does not activate the wheel motors.  &lt;br /&gt;
# is your battery low? are you accelerating too quickly?  &lt;br /&gt;
Because the battery has a high internal resistance, if you demand a lot of power too quickly, the voltage on the battery drops enough that the rPi gets below its critical voltage (when you add the voltage drop from the voltage converter), and the rPi reboots.&lt;br /&gt;
&lt;br /&gt;
To restart donkey server automatically, do the following:   &lt;br /&gt;
* Add this to /etc/rc.local:   &lt;br /&gt;
su - pi -c &#039;cd ~/ohmc_car; python manage.py drive &amp;amp;&amp;gt;/tmp/out&#039; &amp;amp;   &lt;br /&gt;
* move &#039;source ~/env/bin/activate&#039; from ~/.bashrc to ~/.profile&lt;br /&gt;
&lt;br /&gt;
== Steering and throttle calibration ==&lt;br /&gt;
&lt;br /&gt;
To save time at the workshop, you won&#039;t need to calibrate your car&#039;s steering and/or throttle.&lt;br /&gt;
&lt;br /&gt;
However, you may get better results and can perform calibration when you have time ... [http://docs.donkeycar.com/guide/calibrate by following the DonkeyCar instructions]&lt;br /&gt;
&lt;br /&gt;
== Data acquisition for the Neural Network ==&lt;br /&gt;
&lt;br /&gt;
Once you are driving your car confidently around a track ... it is time to acquire training data for the Neural Network.  DonkeyCar operates at 10 frames per second, capturing a 160x120 image, along with steering angle and throttle value.  This is all stored in the &#039;&#039;$HOME/ohmc_car/tub/&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
Before training, it is a good idea to clean out previous data.  Don&#039;t just remove all the files in the &#039;&#039;tub/&#039;&#039; directory !  The &#039;&#039;tub/meta.json&#039;&#039; file is important.&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/train_autopilot Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
Perform the same commands as for manual driving ...&lt;br /&gt;
&lt;br /&gt;
* ssh pi@$IP_ADDRESS&lt;br /&gt;
* cd ohmc_car&lt;br /&gt;
* python manage.py drive&lt;br /&gt;
&lt;br /&gt;
Then via the web browser press the [Start Recording] button ... drive the car around a track ... then press the [Stop Recording] button.&lt;br /&gt;
&lt;br /&gt;
It is recommended that you collect between 5K and 20K frames.  At 10 frames per second, that is between 500 and 2,000 seconds of driving.  Make sure that you drive clockwise and anti-clockwise.&lt;br /&gt;
&lt;br /&gt;
You will need to type this command just once on your DonkeyCar (Raspberry Pi)to provide a directory on your laptop for your training data ...&lt;br /&gt;
&lt;br /&gt;
* rsync -av pi@&amp;lt;car_ip&amp;gt;:ohmc_car .&lt;br /&gt;
&lt;br /&gt;
When finished acquisition, then transfer the data from the DonkeyCar (Raspberry Pi) to your laptop / desktop for training the Neural Network.&lt;br /&gt;
&lt;br /&gt;
* rsync -av pi@&amp;lt;car_ip&amp;gt;:ohmc_car/tub ohmc_car/tub_$DATE&lt;br /&gt;
&lt;br /&gt;
== Training the Neural Network ==&lt;br /&gt;
&lt;br /&gt;
Once training data has been copied to your laptop / desktop, you can begin training the Neural Network.&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/train_autopilot Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
Run these commands on your laptop / desktop to train the Neural Network ...&lt;br /&gt;
&lt;br /&gt;
* workon donkeycar  # For those who have set-up a virtualenv&lt;br /&gt;
* cd ohmc_car&lt;br /&gt;
* python manage.py train --tub $HOME/ohmc_car/tub_$DATE --model ./models/model_$DATE.hdf5&lt;br /&gt;
&lt;br /&gt;
  using donkey version: 2.5.7 ...&lt;br /&gt;
  loading config file: /Users/andyg/play/ai/roba_car/config.py&lt;br /&gt;
  config loaded&lt;br /&gt;
  tub_names ./tub_2019-01-15c&lt;br /&gt;
  train: 5740, validation: 1436&lt;br /&gt;
  steps_per_epoch 44&lt;br /&gt;
  Epoch 1/100&lt;br /&gt;
  2019-01-21 13:08:49.507048: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA&lt;br /&gt;
  43/44 [============================&amp;gt;.] - ETA: 0s - loss: 58.5130 - angle_out_loss: 30.3421 - throttle_out_loss: 86.6839      &lt;br /&gt;
  Epoch 00001: val_loss improved from inf to 0.19699, saving model to ./models/roba0_2019-01-16c.hdf5&lt;br /&gt;
  44/44 [==============================] - 38s 874ms/step - loss: 57.1887 - angle_out_loss: 29.6601 - throttle_out_loss: 84.7172 - val_loss: 0.1970 - val_angle_out_loss: 0.3230 - val_throttle_out_loss: 0.0710&lt;br /&gt;
&lt;br /&gt;
On a modern laptop, each epoch will take around 30 seconds to complete.  For up-to 100 epochs.  Typically, you can expect around 20 to 40 epochs before the Neural Network stop learning.  That is around 10 to 20 minutes of training time.&lt;br /&gt;
&lt;br /&gt;
The training command creates the Neural Network weights that represent what your DonkeyCar has &amp;quot;learned&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
When training has completed, copy the trained model back to your DonkeyCar (Raspberry Pi)&lt;br /&gt;
&lt;br /&gt;
* scp $USERNAME@$HOSTNAME:ohmc_car/models/model_$DATE.hdf5 models&lt;br /&gt;
&lt;br /&gt;
== Self-driving ... the ultimate goal ==&lt;br /&gt;
&lt;br /&gt;
Once your trained model has been copied back onto the DonkeyCar (Raspberry Pi), your car can be self-driven as follow ...&lt;br /&gt;
&lt;br /&gt;
* python manage.py drive --model ~/ohmc_car/models/models/model_$DATE.hdf5&lt;br /&gt;
&lt;br /&gt;
This works similar to the manual driving mode with the addition of a trained model that can either ...&lt;br /&gt;
&lt;br /&gt;
1) User: Manual control of both steering and throttle&lt;br /&gt;
&lt;br /&gt;
2) Local Angle: Automatically control the steering angle&lt;br /&gt;
&lt;br /&gt;
3) Local pilot: Automatically control both the steering angle and throttle amount&lt;br /&gt;
&lt;br /&gt;
The web browser provides a drop-down menu to select between these options.&lt;br /&gt;
&lt;br /&gt;
It is recommended to just start with Local Angle ... and control the throttle manually with the &amp;quot;i&amp;quot; key (faster) and &amp;quot;k&amp;quot; key (slower).&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=OHMC2019_Software_instructions&amp;diff=964</id>
		<title>OHMC2019 Software instructions</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=OHMC2019_Software_instructions&amp;diff=964"/>
		<updated>2019-01-21T07:30:25Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: work around mkvirtualenv not being there&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
From a software perspective, the DonkeyCar (Raspberry Pi) is self-contained ... driving, data acquisition (for training) and ultimately self-driving are all performed with on-board software.  The provided micro-SD card already has all the required software pre-installed, as well as two pre-training A.I / Machine Learning models.  The DonkeyCar software includes a web-server that provides a web interface that works on both desktop and mobile web browsers (great for driving).&lt;br /&gt;
&lt;br /&gt;
Your laptop will be required to perform training of the Neural Network ... using the data acquired on the DonkeyCar.  This means that Python software will need to be installed, e.g TensorFlow (Machine Learning framework).&lt;br /&gt;
&lt;br /&gt;
== Software installation: Laptop / Desktop ==&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/install_software Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
* apt-get install -y virtualenv  # Note: You may be using a different software installer&lt;br /&gt;
* mkvirtualenv donkeycar -p python3&lt;br /&gt;
* pip install tensorflow==1.8.0  # Note: Probably requires Python 3.5 or 3.6.  People are having problems with Python 3.7&lt;br /&gt;
(if you get errors, you can try (re-) installing pip: python -m pip install --upgrade pip )&lt;br /&gt;
&lt;br /&gt;
On debian, if virtualenv isn&#039;t there, try this instead&lt;br /&gt;
* virtualenv donkeycar -p python3&lt;br /&gt;
* cd donkeycar&lt;br /&gt;
* export PATH=`pwd`/bin:$PATH&lt;br /&gt;
* pip install tensorflow==1.8.0&lt;br /&gt;
&lt;br /&gt;
Then proceed:&lt;br /&gt;
&lt;br /&gt;
* git clone https://github.com/autorope/donkeycar&lt;br /&gt;
* pip install -e ./donkeycar&lt;br /&gt;
&lt;br /&gt;
Note: You can manually install Python 3.6 as follows, but then you can&#039;t use mkvirtualenv ...&lt;br /&gt;
&lt;br /&gt;
* yum install python36&lt;br /&gt;
* python3.6 -m venv ~/virtualenvs/donkeycar&lt;br /&gt;
* source ~/virtualenvs/donkeycar/bin/activate&lt;br /&gt;
&lt;br /&gt;
== Software installation: Raspberry Pi ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Your DonkeyCar (Raspberry Pi) is already pre-installed.  This section is for reference only.&lt;br /&gt;
&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/install_software/#get-the-raspberry-pi-working Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
* sysctl -w net.ipv6.conf.all.disable_ipv6=1     # Reconnect via ssh afterwards&lt;br /&gt;
* sysctl -w net.ipv6.conf.default.disable_ipv6=1&lt;br /&gt;
&lt;br /&gt;
* apt-get update&lt;br /&gt;
* apt-get upgrade&lt;br /&gt;
* apt-get install -y vim git mosquitto-clients&lt;br /&gt;
* apt-get install -y virtualenv build-essential python3-dev gfortran libhdf5-dev libatlas-base-dev libopenjp2-7-dev libtiff5&lt;br /&gt;
&lt;br /&gt;
* apt-get install -y i2c-tools&lt;br /&gt;
* i2cdetect -y 1&lt;br /&gt;
         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f&lt;br /&gt;
    00:          -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    70: 70 -- -- -- -- -- -- --&lt;br /&gt;
&lt;br /&gt;
* mv env env.donkeycar&lt;br /&gt;
* virtualenv env -p python3&lt;br /&gt;
* pip install tensorflow==1.8.0&lt;br /&gt;
* pip install adafruit-pca9685&lt;br /&gt;
* pip install picamera&lt;br /&gt;
&lt;br /&gt;
== Finding your car on the network ==&lt;br /&gt;
&lt;br /&gt;
Your DonkeyCar (Raspberry Pi) has been pre-configured to connect to the LCA2019 network.  But, which IP address ?&lt;br /&gt;
&lt;br /&gt;
Every car has a unique hostname, from &#039;&#039;ohmc_01&#039;&#039; to &#039;&#039;ohmc_32&#039;&#039;.  The micro-SD card adapter is labeled with your car name.&lt;br /&gt;
&lt;br /&gt;
However, that still isn&#039;t enough to find your car.&lt;br /&gt;
&lt;br /&gt;
So, there is a &#039;&#039;cron&#039;&#039; job that every minute sends an MQTT message to &#039;&#039;test.mosquitto.org&#039;&#039; with your car&#039;s name, IP address and a timestamp.&lt;br /&gt;
&lt;br /&gt;
Install an MQTT client, as follows ...&lt;br /&gt;
&lt;br /&gt;
* apt-get install mosquitto-clients&lt;br /&gt;
&lt;br /&gt;
Use the following command to read the MQTT messages ...&lt;br /&gt;
&lt;br /&gt;
* mosquitto_sub -h test.mosquitto.org -t &#039;ohmc/#&#039; -v&lt;br /&gt;
&lt;br /&gt;
  ohmc/ohmc_01 10.193.2.69 Mon 11 Jun 07:08:01 UTC 2018&lt;br /&gt;
&lt;br /&gt;
== Driving the car manually ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Caution: Put your car &amp;quot;on blocks&amp;quot; (wheels off the ground) the first time you try driving it&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/get_driving Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
IP_ADDRESS=xxx.xxx.xxx.xxx  # Found as above&lt;br /&gt;
&lt;br /&gt;
* ssh pi@$IP_ADDRESS  # Note: Raspberry Pi default username: &#039;&#039;pi&#039;&#039; and password: &#039;&#039;raspberry&#039;&#039;&lt;br /&gt;
* cd ohmc_car&lt;br /&gt;
* python manage.py drive&lt;br /&gt;
&lt;br /&gt;
  loading config file: /home/pi/play/roba_car/config.py&lt;br /&gt;
  config loaded&lt;br /&gt;
  PiCamera loaded.. .warming camera&lt;br /&gt;
  Starting Donkey Server...&lt;br /&gt;
  You can now go to http://xxx.xxx.xxx.xxx:8887 to drive your car.&lt;br /&gt;
&lt;br /&gt;
With a desktop web browser, the user interface provides a virtual joystick (right-hand frame) that you can use to drive the car ... altering the steering and throttle values.&lt;br /&gt;
&lt;br /&gt;
The mobile web browser, the user interface allows you to drive by tilting the phone left-right for steering and forwards-backwards for throttle.  For safety, you must press the [Start Vehicle] / [Stop Vehicle] toggle button to enable control.&lt;br /&gt;
&lt;br /&gt;
== rPi reboots and Auto-starting donkeycar without logging in ==&lt;br /&gt;
&lt;br /&gt;
If your rPi reboots when you&#039;re driving, check the following things:&lt;br /&gt;
# did you swap the servo wires between steering and power. Turn the ESC off, unplug one servo wire, turn the ESC back on (little toggle switch), and test steering. Make sure that steering does not activate the wheel motors.  &lt;br /&gt;
# is your battery low? are you accelerating too quickly?  &lt;br /&gt;
Because the battery has a high internal resistance, if you demand a lot of power too quickly, the voltage on the battery drops enough that the rPi gets below its critical voltage (when you add the voltage drop from the voltage converter), and the rPi reboots.&lt;br /&gt;
&lt;br /&gt;
To restart donkey server automatically, do the following:   &lt;br /&gt;
* Add this to /etc/rc.local:   &lt;br /&gt;
su - pi -c &#039;cd ~/ohmc_car; python manage.py drive &amp;amp;&amp;gt;/tmp/out&#039; &amp;amp;   &lt;br /&gt;
* move &#039;source ~/env/bin/activate&#039; from ~/.bashrc to ~/.profile&lt;br /&gt;
&lt;br /&gt;
== Steering and throttle calibration ==&lt;br /&gt;
&lt;br /&gt;
To save time at the workshop, you won&#039;t need to calibrate your car&#039;s steering and/or throttle.&lt;br /&gt;
&lt;br /&gt;
However, you may get better results and can perform calibration when you have time ... [http://docs.donkeycar.com/guide/calibrate by following the DonkeyCar instructions]&lt;br /&gt;
&lt;br /&gt;
== Data acquisition for the Neural Network ==&lt;br /&gt;
&lt;br /&gt;
Once you are driving your car confidently around a track ... it is time to acquire training data for the Neural Network.  DonkeyCar operates at 10 frames per second, capturing a 160x120 image, along with steering angle and throttle value.  This is all stored in the &#039;&#039;$HOME/ohmc_car/tub/&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
Before training, it is a good idea to clean out previous data.  Don&#039;t just remove all the files in the &#039;&#039;tub/&#039;&#039; directory !  The &#039;&#039;tub/meta.json&#039;&#039; file is important.&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/train_autopilot Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
Perform the same commands as for manual driving ...&lt;br /&gt;
&lt;br /&gt;
* ssh pi@$IP_ADDRESS&lt;br /&gt;
* cd ohmc_car&lt;br /&gt;
* python manage.py drive&lt;br /&gt;
&lt;br /&gt;
Then via the web browser press the [Start Recording] button ... drive the car around a track ... then press the [Stop Recording] button.&lt;br /&gt;
&lt;br /&gt;
It is recommended that you collect between 5K and 20K frames.  At 10 frames per second, that is between 500 and 2,000 seconds of driving.  Make sure that you drive clockwise and anti-clockwise.&lt;br /&gt;
&lt;br /&gt;
You will need to type this command just once on your DonkeyCar (Raspberry Pi)to provide a directory on your laptop for your training data ...&lt;br /&gt;
&lt;br /&gt;
* scp -pr ohmc_car $USERNAME@$HOSTNAME:&lt;br /&gt;
&lt;br /&gt;
When finished acquisition, then transfer the data from the DonkeyCar (Raspberry Pi) to your laptop / desktop for training the Neural Network.&lt;br /&gt;
&lt;br /&gt;
* scp -pr tub $USERNAME@$HOSTNAME:ohmc_car/tub_$DATE&lt;br /&gt;
&lt;br /&gt;
== Training the Neural Network ==&lt;br /&gt;
&lt;br /&gt;
Once training data has been copied to your laptop / desktop, you can begin training the Neural Network.&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/train_autopilot Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
Run these commands on your laptop / desktop to train the Neural Network ...&lt;br /&gt;
&lt;br /&gt;
* workon donkeycar  # For those who have set-up a virtualenv&lt;br /&gt;
* cd ohmc_car&lt;br /&gt;
* python manage.py train --tub $HOME/ohmc_car/tub_$DATE --model ./models/model_$DATE.hdf5&lt;br /&gt;
&lt;br /&gt;
  using donkey version: 2.5.7 ...&lt;br /&gt;
  loading config file: /Users/andyg/play/ai/roba_car/config.py&lt;br /&gt;
  config loaded&lt;br /&gt;
  tub_names ./tub_2019-01-15c&lt;br /&gt;
  train: 5740, validation: 1436&lt;br /&gt;
  steps_per_epoch 44&lt;br /&gt;
  Epoch 1/100&lt;br /&gt;
  2019-01-21 13:08:49.507048: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA&lt;br /&gt;
  43/44 [============================&amp;gt;.] - ETA: 0s - loss: 58.5130 - angle_out_loss: 30.3421 - throttle_out_loss: 86.6839      &lt;br /&gt;
  Epoch 00001: val_loss improved from inf to 0.19699, saving model to ./models/roba0_2019-01-16c.hdf5&lt;br /&gt;
  44/44 [==============================] - 38s 874ms/step - loss: 57.1887 - angle_out_loss: 29.6601 - throttle_out_loss: 84.7172 - val_loss: 0.1970 - val_angle_out_loss: 0.3230 - val_throttle_out_loss: 0.0710&lt;br /&gt;
&lt;br /&gt;
On a modern laptop, each epoch will take around 30 seconds to complete.  For up-to 100 epochs.  Typically, you can expect around 20 to 40 epochs before the Neural Network stop learning.  That is around 10 to 20 minutes of training time.&lt;br /&gt;
&lt;br /&gt;
The training command creates the Neural Network weights that represent what your DonkeyCar has &amp;quot;learned&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
When training has completed, copy the trained model back to your DonkeyCar (Raspberry Pi)&lt;br /&gt;
&lt;br /&gt;
* scp $USERNAME@$HOSTNAME:ohmc_car/models/model_$DATE.hdf5 models&lt;br /&gt;
&lt;br /&gt;
== Self-driving ... the ultimate goal ==&lt;br /&gt;
&lt;br /&gt;
Once your trained model has been copied back onto the DonkeyCar (Raspberry Pi), your car can be self-driven as follow ...&lt;br /&gt;
&lt;br /&gt;
* python manage.py drive --model ~/ohmc_car/models/models/model_$DATE.hdf5&lt;br /&gt;
&lt;br /&gt;
This works similar to the manual driving mode with the addition of a trained model that can either ...&lt;br /&gt;
&lt;br /&gt;
1) User: Manual control of both steering and throttle&lt;br /&gt;
&lt;br /&gt;
2) Local Angle: Automatically control the steering angle&lt;br /&gt;
&lt;br /&gt;
3) Local pilot: Automatically control both the steering angle and throttle amount&lt;br /&gt;
&lt;br /&gt;
The web browser provides a drop-down menu to select between these options.&lt;br /&gt;
&lt;br /&gt;
It is recommended to just start with Local Angle ... and control the throttle manually with the &amp;quot;i&amp;quot; key (faster) and &amp;quot;k&amp;quot; key (slower).&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=OHMC2019_Software_instructions&amp;diff=963</id>
		<title>OHMC2019 Software instructions</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=OHMC2019_Software_instructions&amp;diff=963"/>
		<updated>2019-01-21T06:11:42Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: Added info on how to deal with rPi reboots&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
From a software perspective, the DonkeyCar (Raspberry Pi) is self-contained ... driving, data acquisition (for training) and ultimately self-driving are all performed with on-board software.  The provided micro-SD card already has all the required software pre-installed, as well as two pre-training A.I / Machine Learning models.  The DonkeyCar software includes a web-server that provides a web interface that works on both desktop and mobile web browsers (great for driving).&lt;br /&gt;
&lt;br /&gt;
Your laptop will be required to perform training of the Neural Network ... using the data acquired on the DonkeyCar.  This means that Python software will need to be installed, e.g TensorFlow (Machine Learning framework).&lt;br /&gt;
&lt;br /&gt;
== Software installation: Laptop / Desktop ==&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/install_software Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
* apt-get install -y virtualenv  # Note: You may be using a different software installer&lt;br /&gt;
* mkvirtualenv donkeycar -p python3&lt;br /&gt;
* pip install tensorflow==1.8.0  # Note: Probably requires Python 3.5 or 3.6.  People are having problems with Python 3.7&lt;br /&gt;
(if you get errors, you can try (re-) installing pip: python -m pip install --upgrade pip )&lt;br /&gt;
&lt;br /&gt;
* cd $HOME&lt;br /&gt;
* git clone https://github.com/autorope/donkeycar&lt;br /&gt;
* pip install -e ./donkeycar&lt;br /&gt;
&lt;br /&gt;
Note: You can manually install Python 3.6 as follows, but then you can&#039;t use mkvirtualenv ...&lt;br /&gt;
&lt;br /&gt;
* yum install python36&lt;br /&gt;
* python3.6 -m venv ~/virtualenvs/donkeycar&lt;br /&gt;
* source ~/virtualenvs/donkeycar/bin/activate&lt;br /&gt;
&lt;br /&gt;
== Software installation: Raspberry Pi ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Your DonkeyCar (Raspberry Pi) is already pre-installed.  This section is for reference only.&lt;br /&gt;
&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/install_software/#get-the-raspberry-pi-working Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
* sysctl -w net.ipv6.conf.all.disable_ipv6=1     # Reconnect via ssh afterwards&lt;br /&gt;
* sysctl -w net.ipv6.conf.default.disable_ipv6=1&lt;br /&gt;
&lt;br /&gt;
* apt-get update&lt;br /&gt;
* apt-get upgrade&lt;br /&gt;
* apt-get install -y vim git mosquitto-clients&lt;br /&gt;
* apt-get install -y virtualenv build-essential python3-dev gfortran libhdf5-dev libatlas-base-dev libopenjp2-7-dev libtiff5&lt;br /&gt;
&lt;br /&gt;
* apt-get install -y i2c-tools&lt;br /&gt;
* i2cdetect -y 1&lt;br /&gt;
         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f&lt;br /&gt;
    00:          -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    70: 70 -- -- -- -- -- -- --&lt;br /&gt;
&lt;br /&gt;
* mv env env.donkeycar&lt;br /&gt;
* virtualenv env -p python3&lt;br /&gt;
* pip install tensorflow==1.8.0&lt;br /&gt;
* pip install adafruit-pca9685&lt;br /&gt;
* pip install picamera&lt;br /&gt;
&lt;br /&gt;
== Finding your car on the network ==&lt;br /&gt;
&lt;br /&gt;
Your DonkeyCar (Raspberry Pi) has been pre-configured to connect to the LCA2019 network.  But, which IP address ?&lt;br /&gt;
&lt;br /&gt;
Every car has a unique hostname, from &#039;&#039;ohmc_01&#039;&#039; to &#039;&#039;ohmc_32&#039;&#039;.  The micro-SD card adapter is labeled with your car name.&lt;br /&gt;
&lt;br /&gt;
However, that still isn&#039;t enough to find your car.&lt;br /&gt;
&lt;br /&gt;
So, there is a &#039;&#039;cron&#039;&#039; job that every minute sends an MQTT message to &#039;&#039;test.mosquitto.org&#039;&#039; with your car&#039;s name, IP address and a timestamp.&lt;br /&gt;
&lt;br /&gt;
Install an MQTT client, as follows ...&lt;br /&gt;
&lt;br /&gt;
* apt-get install mosquitto-clients&lt;br /&gt;
&lt;br /&gt;
Use the following command to read the MQTT messages ...&lt;br /&gt;
&lt;br /&gt;
* mosquitto_sub -h test.mosquitto.org -t &#039;ohmc/#&#039; -v&lt;br /&gt;
&lt;br /&gt;
  ohmc/ohmc_01 10.193.2.69 Mon 11 Jun 07:08:01 UTC 2018&lt;br /&gt;
&lt;br /&gt;
== Driving the car manually ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Caution: Put your car &amp;quot;on blocks&amp;quot; (wheels off the ground) the first time you try driving it&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/get_driving Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
IP_ADDRESS=xxx.xxx.xxx.xxx  # Found as above&lt;br /&gt;
&lt;br /&gt;
* ssh pi@$IP_ADDRESS  # Note: Raspberry Pi default username: &#039;&#039;pi&#039;&#039; and password: &#039;&#039;raspberry&#039;&#039;&lt;br /&gt;
* cd ohmc_car&lt;br /&gt;
* python manage.py drive&lt;br /&gt;
&lt;br /&gt;
  loading config file: /home/pi/play/roba_car/config.py&lt;br /&gt;
  config loaded&lt;br /&gt;
  PiCamera loaded.. .warming camera&lt;br /&gt;
  Starting Donkey Server...&lt;br /&gt;
  You can now go to http://xxx.xxx.xxx.xxx:8887 to drive your car.&lt;br /&gt;
&lt;br /&gt;
With a desktop web browser, the user interface provides a virtual joystick (right-hand frame) that you can use to drive the car ... altering the steering and throttle values.&lt;br /&gt;
&lt;br /&gt;
The mobile web browser, the user interface allows you to drive by tilting the phone left-right for steering and forwards-backwards for throttle.  For safety, you must press the [Start Vehicle] / [Stop Vehicle] toggle button to enable control.&lt;br /&gt;
&lt;br /&gt;
== rPi reboots and Auto-starting donkeycar without logging in ==&lt;br /&gt;
&lt;br /&gt;
If your rPi reboots when you&#039;re driving, check the following things:&lt;br /&gt;
# did you swap the servo wires between steering and power. Turn the ESC off, unplug one servo wire, turn the ESC back on (little toggle switch), and test steering. Make sure that steering does not activate the wheel motors.  &lt;br /&gt;
# is your battery low? are you accelerating too quickly?  &lt;br /&gt;
Because the battery has a high internal resistance, if you demand a lot of power too quickly, the voltage on the battery drops enough that the rPi gets below its critical voltage (when you add the voltage drop from the voltage converter), and the rPi reboots.&lt;br /&gt;
&lt;br /&gt;
To restart donkey server automatically, do the following:   &lt;br /&gt;
* Add this to /etc/rc.local:   &lt;br /&gt;
su - pi -c &#039;cd ~/ohmc_car; python manage.py drive &amp;amp;&amp;gt;/tmp/out&#039; &amp;amp;   &lt;br /&gt;
* move &#039;source ~/env/bin/activate&#039; from ~/.bashrc to ~/.profile&lt;br /&gt;
&lt;br /&gt;
== Steering and throttle calibration ==&lt;br /&gt;
&lt;br /&gt;
To save time at the workshop, you won&#039;t need to calibrate your car&#039;s steering and/or throttle.&lt;br /&gt;
&lt;br /&gt;
However, you may get better results and can perform calibration when you have time ... [http://docs.donkeycar.com/guide/calibrate by following the DonkeyCar instructions]&lt;br /&gt;
&lt;br /&gt;
== Data acquisition for the Neural Network ==&lt;br /&gt;
&lt;br /&gt;
Once you are driving your car confidently around a track ... it is time to acquire training data for the Neural Network.  DonkeyCar operates at 10 frames per second, capturing a 160x120 image, along with steering angle and throttle value.  This is all stored in the &#039;&#039;$HOME/ohmc_car/tub/&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
Before training, it is a good idea to clean out previous data.  Don&#039;t just remove all the files in the &#039;&#039;tub/&#039;&#039; directory !  The &#039;&#039;tub/meta.json&#039;&#039; file is important.&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/train_autopilot Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
Perform the same commands as for manual driving ...&lt;br /&gt;
&lt;br /&gt;
* ssh pi@$IP_ADDRESS&lt;br /&gt;
* cd ohmc_car&lt;br /&gt;
* python manage.py drive&lt;br /&gt;
&lt;br /&gt;
Then via the web browser press the [Start Recording] button ... drive the car around a track ... then press the [Stop Recording] button.&lt;br /&gt;
&lt;br /&gt;
It is recommended that you collect between 5K and 20K frames.  At 10 frames per second, that is between 500 and 2,000 seconds of driving.  Make sure that you drive clockwise and anti-clockwise.&lt;br /&gt;
&lt;br /&gt;
You will need to type this command just once on your DonkeyCar (Raspberry Pi)to provide a directory on your laptop for your training data ...&lt;br /&gt;
&lt;br /&gt;
* scp -pr ohmc_car $USERNAME@$HOSTNAME:&lt;br /&gt;
&lt;br /&gt;
When finished acquisition, then transfer the data from the DonkeyCar (Raspberry Pi) to your laptop / desktop for training the Neural Network.&lt;br /&gt;
&lt;br /&gt;
* scp -pr tub $USERNAME@$HOSTNAME:ohmc_car/tub_$DATE&lt;br /&gt;
&lt;br /&gt;
== Training the Neural Network ==&lt;br /&gt;
&lt;br /&gt;
Once training data has been copied to your laptop / desktop, you can begin training the Neural Network.&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/train_autopilot Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
Run these commands on your laptop / desktop to train the Neural Network ...&lt;br /&gt;
&lt;br /&gt;
* workon donkeycar  # For those who have set-up a virtualenv&lt;br /&gt;
* cd ohmc_car&lt;br /&gt;
* python manage.py train --tub $HOME/ohmc_car/tub_$DATE --model ./models/model_$DATE.hdf5&lt;br /&gt;
&lt;br /&gt;
  using donkey version: 2.5.7 ...&lt;br /&gt;
  loading config file: /Users/andyg/play/ai/roba_car/config.py&lt;br /&gt;
  config loaded&lt;br /&gt;
  tub_names ./tub_2019-01-15c&lt;br /&gt;
  train: 5740, validation: 1436&lt;br /&gt;
  steps_per_epoch 44&lt;br /&gt;
  Epoch 1/100&lt;br /&gt;
  2019-01-21 13:08:49.507048: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA&lt;br /&gt;
  43/44 [============================&amp;gt;.] - ETA: 0s - loss: 58.5130 - angle_out_loss: 30.3421 - throttle_out_loss: 86.6839      &lt;br /&gt;
  Epoch 00001: val_loss improved from inf to 0.19699, saving model to ./models/roba0_2019-01-16c.hdf5&lt;br /&gt;
  44/44 [==============================] - 38s 874ms/step - loss: 57.1887 - angle_out_loss: 29.6601 - throttle_out_loss: 84.7172 - val_loss: 0.1970 - val_angle_out_loss: 0.3230 - val_throttle_out_loss: 0.0710&lt;br /&gt;
&lt;br /&gt;
On a modern laptop, each epoch will take around 30 seconds to complete.  For up-to 100 epochs.  Typically, you can expect around 20 to 40 epochs before the Neural Network stop learning.  That is around 10 to 20 minutes of training time.&lt;br /&gt;
&lt;br /&gt;
The training command creates the Neural Network weights that represent what your DonkeyCar has &amp;quot;learned&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
When training has completed, copy the trained model back to your DonkeyCar (Raspberry Pi)&lt;br /&gt;
&lt;br /&gt;
* scp $USERNAME@$HOSTNAME:ohmc_car/models/model_$DATE.hdf5 models&lt;br /&gt;
&lt;br /&gt;
== Self-driving ... the ultimate goal ==&lt;br /&gt;
&lt;br /&gt;
Once your trained model has been copied back onto the DonkeyCar (Raspberry Pi), your car can be self-driven as follow ...&lt;br /&gt;
&lt;br /&gt;
* python manage.py drive --model ~/ohmc_car/models/models/model_$DATE.hdf5&lt;br /&gt;
&lt;br /&gt;
This works similar to the manual driving mode with the addition of a trained model that can either ...&lt;br /&gt;
&lt;br /&gt;
1) User: Manual control of both steering and throttle&lt;br /&gt;
&lt;br /&gt;
2) Local Angle: Automatically control the steering angle&lt;br /&gt;
&lt;br /&gt;
3) Local pilot: Automatically control both the steering angle and throttle amount&lt;br /&gt;
&lt;br /&gt;
The web browser provides a drop-down menu to select between these options.&lt;br /&gt;
&lt;br /&gt;
It is recommended to just start with Local Angle ... and control the throttle manually with the &amp;quot;i&amp;quot; key (faster) and &amp;quot;k&amp;quot; key (slower).&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=OHMC2019_Software_instructions&amp;diff=951</id>
		<title>OHMC2019 Software instructions</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=OHMC2019_Software_instructions&amp;diff=951"/>
		<updated>2019-01-20T23:07:16Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
From a software perspective, the DonkeyCar (Raspberry Pi) is self-contained ... driving, data acquisition (for training) and ultimately self-driving are all performed with on-board software.  The provided micro-SD card already has all the required software pre-installed, as well as two pre-training A.I / Machine Learning models.  The DonkeyCar software includes a web-server that provides a web interface that works on both desktop and mobile web browsers (great for driving).&lt;br /&gt;
&lt;br /&gt;
Your laptop will be required to perform training of the Neural Network ... using the data acquired on the DonkeyCar.  This means that Python software will need to be installed, e.g TensorFlow (Machine Learning framework).&lt;br /&gt;
&lt;br /&gt;
== Software installation: Laptop / Desktop ==&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/install_software Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
* apt-get install -y virtualenv  # Note: You may be using a different software installer&lt;br /&gt;
* mkvirtualenv donkeycar -p python3&lt;br /&gt;
* pip install tensorflow==1.8.0&lt;br /&gt;
(if you get errors, you can try (re-) installing pip: python -m pip install --upgrade pip )&lt;br /&gt;
&lt;br /&gt;
* cd $HOME&lt;br /&gt;
* git clone https://github.com/autorope/donkeycar&lt;br /&gt;
* pip install -e ./donkeycar&lt;br /&gt;
&lt;br /&gt;
== Software installation: Raspberry Pi ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Your DonkeyCar (Raspberry Pi) is already pre-installed.  This section is for reference only.&lt;br /&gt;
&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/install_software/#get-the-raspberry-pi-working Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
* sysctl -w net.ipv6.conf.all.disable_ipv6=1     # Reconnect via ssh afterwards&lt;br /&gt;
* sysctl -w net.ipv6.conf.default.disable_ipv6=1&lt;br /&gt;
&lt;br /&gt;
* apt-get update&lt;br /&gt;
* apt-get upgrade&lt;br /&gt;
* apt-get install -y vim git mosquitto-clients&lt;br /&gt;
* apt-get install -y virtualenv build-essential python3-dev gfortran libhdf5-dev libatlas-base-dev libopenjp2-7-dev libtiff5&lt;br /&gt;
&lt;br /&gt;
* apt-get install -y i2c-tools&lt;br /&gt;
* i2cdetect -y 1&lt;br /&gt;
         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f&lt;br /&gt;
    00:          -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --&lt;br /&gt;
    70: 70 -- -- -- -- -- -- --&lt;br /&gt;
&lt;br /&gt;
* mv env env.donkeycar&lt;br /&gt;
* virtualenv env -p python3&lt;br /&gt;
* pip install tensorflow==1.8.0&lt;br /&gt;
* pip install adafruit-pca9685&lt;br /&gt;
* pip install picamera&lt;br /&gt;
&lt;br /&gt;
== Finding your car on the network ==&lt;br /&gt;
&lt;br /&gt;
Your DonkeyCar (Raspberry Pi) has been pre-configured to connect to the LCA2019 network.  But, which IP address ?&lt;br /&gt;
&lt;br /&gt;
Every car has a unique hostname, from &#039;&#039;ohmc_01&#039;&#039; to &#039;&#039;ohmc_32&#039;&#039;.  The micro-SD card adapter is labeled with your car name.&lt;br /&gt;
&lt;br /&gt;
However, that still isn&#039;t enough to find your car.&lt;br /&gt;
&lt;br /&gt;
So, there is a &#039;&#039;cron&#039;&#039; job that every minute sends an MQTT message to &#039;&#039;test.mosquitto.org&#039;&#039; with your car&#039;s name, IP address and a timestamp.&lt;br /&gt;
&lt;br /&gt;
Install an MQTT client, as follows ...&lt;br /&gt;
&lt;br /&gt;
* apt-get install mosquitto-clients&lt;br /&gt;
&lt;br /&gt;
Use the following command to read the MQTT messages ...&lt;br /&gt;
&lt;br /&gt;
* mosquitto_sub -h test.mosquitto.org -t &#039;ohmc/#&#039; -v&lt;br /&gt;
&lt;br /&gt;
  ohmc/ohmc_01 10.193.2.69 Mon 11 Jun 07:08:01 UTC 2018&lt;br /&gt;
&lt;br /&gt;
== Driving the car manually ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Caution: Put your car &amp;quot;on blocks&amp;quot; (wheels off the ground) the first time you try driving it&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[http://docs.donkeycar.com/guide/get_driving Extensive DonkeyCar documentation]&lt;br /&gt;
&lt;br /&gt;
IP_ADDRESS=xxx.xxx.xxx.xxx  # Found as above&lt;br /&gt;
&lt;br /&gt;
* ssh pi@$IP_ADDRESS&lt;br /&gt;
* cd ohmc_car&lt;br /&gt;
* python manage.py drive&lt;br /&gt;
&lt;br /&gt;
  loading config file: /home/pi/play/roba_car/config.py&lt;br /&gt;
  config loaded&lt;br /&gt;
  PiCamera loaded.. .warming camera&lt;br /&gt;
  Starting Donkey Server...&lt;br /&gt;
  You can now go to http://xxx.xxx.xxx.xxx:8887 to drive your car.&lt;br /&gt;
&lt;br /&gt;
With a desktop web browser, the user interface provides a virtual joystick (right-hand frame) that you can use to drive the car ... altering the steering and throttle values.&lt;br /&gt;
&lt;br /&gt;
The mobile web browser, the user interface allows you to drive by tilting the phone left-right for steering and forwards-backwards for throttle.  For safety, you must press the [Start Vehicle] / [Stop Vehicle] toggle button to enable control.&lt;br /&gt;
&lt;br /&gt;
== Steering and throttle calibration ==&lt;br /&gt;
&lt;br /&gt;
To save time at the workshop, you won&#039;t need to calibrate your car&#039;s steering and/or throttle.&lt;br /&gt;
&lt;br /&gt;
However, you may get better results and can perform calibration when you have time ... [http://docs.donkeycar.com/guide/calibrate by following the DonkeyCar instructions]&lt;br /&gt;
&lt;br /&gt;
== Data acquisition for the Neural Network ==&lt;br /&gt;
&lt;br /&gt;
== Training the Neural Network ==&lt;br /&gt;
&lt;br /&gt;
== Self-driving the car ==&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Pebble_V2.0_Instructions&amp;diff=110</id>
		<title>Pebble V2.0 Instructions</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Pebble_V2.0_Instructions&amp;diff=110"/>
		<updated>2012-01-27T08:03:49Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Hardware Overview ==&lt;br /&gt;
&lt;br /&gt;
* Arduino Uno compatible, with ATmega328 and ATmega8U2 carrying the appropriate bootloaders.&lt;br /&gt;
* Boost-converter power supply for portable battery operation at battery voltages between 2.4-4.5 volts.&lt;br /&gt;
* RGB LED with each of the 3 LEDs independently programmable, including PWM capability.&lt;br /&gt;
* Standard HD44780 20x4 alphanumeric LCD display.&lt;br /&gt;
* Support for a low cost Nintendo DS style 4-wire resistive touchscreen (not included in the kit for LCA2012)&lt;br /&gt;
* Support for an XBee 802.15.4 radio module or any other &amp;quot;Bee&amp;quot;-compatible module that operates at 3.3V and talks to a serial UART (not included in the kit for LCA2012)&lt;br /&gt;
* Two general-purpose open-collector low-side-switching output transistors for controlling external devices such as relays.&lt;br /&gt;
* Rotary encoder for user input.&lt;br /&gt;
* Temperature sensor (MCP9701) and light sensor (TEMT6000).&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a basic guide to assembling a Pebble (Mk. 2) kit. In your kit, all the SMD components are pre-soldered on the board, the ATmega8U2 USB-to-serial circuit on the board has been pre-tested and the ATmega8U2 flashed appropriately, and the ATmega328 microcontroller has been pre-flashed with an appropriate Arduino Uno compatible bootloader.&lt;br /&gt;
&lt;br /&gt;
Now, let&#039;s start assembling the through-hole components on the board. Don&#039;t worry, it&#039;s all pretty easy to assemble.&lt;br /&gt;
&lt;br /&gt;
[[File:IMAG0615.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Kit Assembly (only the through-hole components)==&lt;br /&gt;
&lt;br /&gt;
=== Terminal Blocks, Electrolytic Capacitors, Trimpot===&lt;br /&gt;
&lt;br /&gt;
We will start by installing the 2-pin screw terminal block for the battery connection, in the upper left of the board. Make sure that the holes where the wires are inserted into the terminals face out towards the outside edge of the board. The sloped face need to face outwards. Next, we will also insert and solder the two 220 uF electrolytic capacitors in the upper left of the board. The capacitors are polarised, they need to be inserted into the board with the negative lead (the one marked with a stripe down the length of the capacitor body) inserted into the hole marked &amp;quot;-&amp;quot;, and the positive lead (which should be longer) inserted into the hole marked &amp;quot;+&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The 10uH inductor is a large round cotton reel shaped component. It is not polarised. You will find that you are not able to mount it flush with the board, so just push it down firmly until it won&#039;t go any lower.&lt;br /&gt;
&lt;br /&gt;
[[File:IMAG0619.jpg]]&lt;br /&gt;
&lt;br /&gt;
We will also fit the shorting jumper onto the two-pin header at this stage. &lt;br /&gt;
&lt;br /&gt;
The trimpot is used to adjust the LCD display contrast and is mounted in one way. Insert and solder the trimpot onto the board. It can only be inserted one way.&lt;br /&gt;
&lt;br /&gt;
[[File:IMAG0624.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Headers ===&lt;br /&gt;
&lt;br /&gt;
Insert and solder the two 6-pin ISP programming headers, which have 2 rows of three pins. The ISP programming headers make a very snug fit into their holes on the PCB, and you may need to use some sort of tool (The end of the handle of a screwdriver or cutters) to apply firm pressure to press these fully down into place.&lt;br /&gt;
&lt;br /&gt;
Insert and solder the 16-pin male header strip which connects to the LCD display.&lt;br /&gt;
&lt;br /&gt;
Insert and solder the pair of 8-pin female header strips and the pair of 6-pin female header strips that are used to mate with Arduino &amp;quot;shields&amp;quot;. The female headers don&#039;t always sit straight in the holes, so make sure you hold them straight while you solder just one of the pins to start with. Then you can adjust the alignment of the headers before soldering the rest of the pins.&lt;br /&gt;
&lt;br /&gt;
[[File:IMAG0628.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== RGB LED ===&lt;br /&gt;
&lt;br /&gt;
The RGB LED is a rounded, milky-coloured part with 4 long leads coming out one end.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note: The RGB LED must be inserted the correct way, with the flat side of the LED corresponding to the silkscreen marking. One of the LED pins is longer than the others, and one of the holes in the PCB has a square pad. The long lead goes into the square pad.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have any doubt about the orientation of the RGB LED please ask for help. Soldering it in only takes a moment, but getting it back out again can be extremely difficult!&lt;br /&gt;
&lt;br /&gt;
The four leads of the RGB LED will need to kind of splay out on an angle as you insert the LED onto the board, so it will end up sitting up approximately 5 mm off the board and it will not sit completely flush with the board. After ensuring that you have it oriented correctly, insert and solder in the RGB LED.&lt;br /&gt;
&lt;br /&gt;
=== DIP Socket ===&lt;br /&gt;
Insert and solder the 28-pin DIP socket for the AVR microcontroller.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The IC socket should be inserted so that the pin-1 indicator notch on the socket corresponds to the silkscreen marking, with the notch to the right if you&#039;re holding the PCB as shown below.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:IMAG0631.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== MCP9701 Temperature Sensor and 2N2222 Transistors ===&lt;br /&gt;
&lt;br /&gt;
In the bottom right hand corner you will find three semi-circular shapes on the silscreen, which are for one MCP9701 temperature sensors and two 2N2222 transistors. All three parts are in &amp;quot;TO-92&amp;quot; packages, and look absolutely identical.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Careful! Don&#039;t get them mixed up and put the parts in the wrong spots. They are not interchangeable.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The only way to tell them apart is by looking at the extremely small printing on the face of the part. If you have trouble reading them, don&#039;t guess. There are magnifying glasses at the front of the room.  To help ensure that you don&#039;t get them confused, it could be a good idea to separate out the MCP9701 and put the two P2N2222 transistors back in the bag or parts tray until you&#039;re ready to fit them.&lt;br /&gt;
&lt;br /&gt;
The MCP9701 is mounted facing the bottom edge near the mounting hole, in the location labelled &amp;quot;Temp&amp;quot;. Insert it and gently push it down until the body is about 5 to 8mm clear of the PCB. The leads will need to splay out a little to fit. Solder it in place carefully, doing each joint quickly and then letting the part cool down for a few seconds before doing the next one.&lt;br /&gt;
&lt;br /&gt;
Insert and solder the two transistors in the same way.&lt;br /&gt;
&lt;br /&gt;
==== Xbee Headers ====&lt;br /&gt;
It can be easier to hold the XBee header sockets in if you have an XBee module handy, by inserting the sockets onto the pins of the XBee module first and then inserting this assembly into the holes on the board. If you don&#039;t have an XBee module and don&#039;t intend to fit one, you can simply leave those headers off the board.&lt;br /&gt;
&lt;br /&gt;
=== Rotary Encoder===&lt;br /&gt;
Now we&#039;ll also insert and solder the rotary encoder. It should &amp;quot;snap&amp;quot; into place on the board as its mechanical mounting tabs are inserted into the PCB. The tabs can be tricky to clip in though and you need to be careful not to bend the thin leads while wrestling with the mounting tabs. You may find it helpful to get the part fully aligned and then use a tiny screwdriver or similar to push the tabs sideways until they clip in.&lt;br /&gt;
&lt;br /&gt;
=== LCD Module Header===&lt;br /&gt;
Unpack the LCD module and solder a 16-way pin male header onto its connection pads, with the header on the bottom of the PCB. The LCD connects to the Pebble via a ribbon cable (also supplied) so you can mount the display separately. When plugging them all together, make sure that pin 1 on the header on the PCB connects via the cable to pin 1 on the header on the LCD. One way to check is to hold the LCD directly over the PCB as if it was going to mount over the top of it, in which case the pins on the two sets of headers will naturally align correctly.&lt;br /&gt;
&lt;br /&gt;
=== ATmega328P Microcontroller ===&lt;br /&gt;
&#039;&#039;&#039;Warning: the MCU is a static-sensitive part. Minimise your handling of the pins once it has been removed from its protective anti-static foam.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The orientation of the MCU is critical. Pin 1 is noted by a notch at one end of the IC. It may be hidden by the sticker but should be revealed by pushing the sticker back a little. Ask if you are not sure. You will find that the legs of the IC may not line up correctly with holes in the socket. Please do not force it as that trick never works. Instead use a flat surface such as the workbench to push the legs in a little bit and then repeat for the other side. The trick is to be &amp;quot;firm, but not brutal&amp;quot; - it can take a reasonable amount of force to bend all the pins straight, but it&#039;s easy to overdo it and fold them over. Once again, please ask for help with this step if unsure.&lt;br /&gt;
&lt;br /&gt;
[[File:IMAG0638.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Testing===&lt;br /&gt;
&lt;br /&gt;
Plug in the USB cable (which we&#039;ve included for you) into a PC and into the Pebble board, and the blue power LED should light, and the new USB device should be recognized by the OS. If the power LED does not light, you &#039;&#039;&#039;did&#039;&#039;&#039; install the jumper to short out the USB power disconnection header, right? (Note that the power switch doesn&#039;t do anything except when battery power is used. If USB power is connected, then it is &amp;quot;always on&amp;quot;.)&lt;br /&gt;
&lt;br /&gt;
At this stage, you should be able to talk to the board from the PC. It&#039;s completely compatible with the Arduino Uno, but we re-used the same firmware used on the Freetronics Eleven, so it identifies itself as a Freetronics Eleven.&lt;br /&gt;
&lt;br /&gt;
If your PC is running Windows, you&#039;ll need to [http://www.freetronics.com/pages/installing-the-usb-driver-file-for-windows install the driver] if you&#039;ve never used an Arduino Uno or compatible device on your PC before. If you&#039;re running Linux or Mac OSX etc, then it should just work without any effort.&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also need to have the Arduino IDE installed, of course. Select &amp;quot;Arduino Uno&amp;quot; as the target hardware type, select the right (virtual) serial port for the Arduino IDE to talk to, and you should be all ready to upload programs.&lt;br /&gt;
&lt;br /&gt;
If you want to use the LCD, you’ll need to attach the LCD display. This is done by making sure that your LCD display has a 16-pin header soldered onto it, and connecting the 16-wire ribbon cable to both the LCD display and the LCD header on the main board, making sure that &#039;&#039;&#039;pin 1 on the Pebble board is connected to pin 1 on the LCD display&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Demo Software===&lt;br /&gt;
&lt;br /&gt;
If you want test code, you can look at [http://marc.merlins.org/perso/arduino/post_2012-01-24_Much-Improved-Pebble-v2-Aiko-Demo-Code.html Marc MERLIN&#039;s page with a full test for most of the Pebble v2&#039;s hardware] (note the few example standalone programs that do not use Aiko at the end of that page, and hosted on https://github.com/marcmerlin/pebble_v2_demos ).&lt;br /&gt;
&lt;br /&gt;
Marc&#039;s code was based on Andy&#039;s original work on github: https://github.com/geekscape/aiko_pebble_v2 .&lt;br /&gt;
&lt;br /&gt;
===Hardware Features===&lt;br /&gt;
&lt;br /&gt;
* Arduino Uno compatible, with ATmega328 and ATmega8U2 carrying the appropriate bootloaders.&lt;br /&gt;
* Boost-converter power supply for portable battery operation at battery voltages between 2.4-4.5 volts.&lt;br /&gt;
* RGB LED with each of the 3 LEDs independently programmable, including PWM capability.&lt;br /&gt;
* Standard HD44780 20x4 alphanumeric LCD display.&lt;br /&gt;
* Support for a low cost Nintendo DS style 4-wire resistive touchscreen.&lt;br /&gt;
* Support for an XBee 802.15.4 radio module or any other &amp;quot;Bee&amp;quot;-compatible module that operates at 3.3V and talks to a serial UART.&lt;br /&gt;
* Two general-purpose open-collector low-side-switching output transistors for controlling external devices such as relays.&lt;br /&gt;
* Rotary encoder for user input.&lt;br /&gt;
* Temperature sensor (MCP9701) and light sensor (TEMT6000).&lt;br /&gt;
&lt;br /&gt;
===Battery power===&lt;br /&gt;
&lt;br /&gt;
Now, if you want to use portable power without just being limited to USB use, let’s look at power options.&lt;br /&gt;
&lt;br /&gt;
After you&#039;ve programmed the board with some code, if you want to use an alternative power source away from your PC, you can either use battery power or you can provide regulated 5.0 V DC power to the USB socket via a standard USB cable - for example by using one of those common 5.0V mains switchmode plugpacks with a &amp;quot;dumb&amp;quot; USB connector for power output.&lt;br /&gt;
&lt;br /&gt;
The battery voltage input must be within the range of about 2.4 - 4.5 V for correct operation. &#039;&#039;&#039;Thou shall not ever exceed 5 volts&#039;&#039;&#039;, into either of the power supply inputs, on this device.&lt;br /&gt;
&lt;br /&gt;
You can use two standard alkaline or NiCd or NiMH cells in series, for a voltage supply of 3.0 V (or 2.4 V if you’re using 1.2 V NiMH cells), or you can use 3.6-4.5 V from a set of three cells in series. The latter will provide an improvement in battery life. The 2.4 V you will get from two NiMH cells is OK, but it is towards the lower end of the operational voltage window.&lt;br /&gt;
&lt;br /&gt;
You can use common “AA” or “AAA” cells, however the larger types such as “C” or “D” cells will provide greater charge capacity and a greater runtime. You could also use a 3.7 V lithium-polymer cell, where a small, lightweight battery with high energy density is desired. (Note that there is no battery holder included with the kit and you can add your own separately if you want to use battery power.)&lt;br /&gt;
&lt;br /&gt;
Make sure that the positive and negative wires from the battery holder are connected to the terminal block on the board with the correct polarity, as marked on the silkscreen, and ensure that charged batteries are inserted into the battery holder with the correct polarity. With the batteries installed and wired up, you should then be able to turn on the power switch on the board, and the power LED should light up. (The on-board power switch has no effect if USB power is connected.) If you’re using a battery holder which has a built-in power switch then this power switch must also be turned on.&lt;br /&gt;
&lt;br /&gt;
There is no battery charging electronics built into the device - to recharge your batteries they must be disconnected and recharged externally.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Semi-permanent solder jumpers===&lt;br /&gt;
&lt;br /&gt;
SJ1 is normally closed, this is for automatic reset of the AVR, controlled by the USB UART interface, during programming. Cut it to disable auto-reset.&amp;lt;br&amp;gt;&lt;br /&gt;
SJ2 connects the USB shield to ground. This is normally closed and should never normally need to be opened.&amp;lt;br&amp;gt;&lt;br /&gt;
SJ3 is normally open. This is for the DFU programming of the ATmega16U2 and should never need to be closed.&amp;lt;br&amp;gt;&lt;br /&gt;
SJ4 is normally closed, and this connects the high side of the two low-side-switching open collector output transistors to +5V. Disconnect it if you want to use an external higher-voltage power supply for these circuits.&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
	<entry>
		<id>http://www.openhardwareconf.org/index.php?title=Pebble_V2.0_Instructions&amp;diff=109</id>
		<title>Pebble V2.0 Instructions</title>
		<link rel="alternate" type="text/html" href="http://www.openhardwareconf.org/index.php?title=Pebble_V2.0_Instructions&amp;diff=109"/>
		<updated>2012-01-27T07:58:37Z</updated>

		<summary type="html">&lt;p&gt;Marcmerlin: /* Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Hardware Overview ==&lt;br /&gt;
&lt;br /&gt;
* Arduino Uno compatible, with ATmega328 and ATmega8U2 carrying the appropriate bootloaders.&lt;br /&gt;
* Boost-converter power supply for portable battery operation at battery voltages between 2.4-4.5 volts.&lt;br /&gt;
* RGB LED with each of the 3 LEDs independently programmable, including PWM capability.&lt;br /&gt;
* Standard HD44780 20x4 alphanumeric LCD display.&lt;br /&gt;
* Support for a low cost Nintendo DS style 4-wire resistive touchscreen (not included in the kit for LCA2012)&lt;br /&gt;
* Support for an XBee 802.15.4 radio module or any other &amp;quot;Bee&amp;quot;-compatible module that operates at 3.3V and talks to a serial UART (not included in the kit for LCA2012)&lt;br /&gt;
* Two general-purpose open-collector low-side-switching output transistors for controlling external devices such as relays.&lt;br /&gt;
* Rotary encoder for user input.&lt;br /&gt;
* Temperature sensor (MCP9701) and light sensor (TEMT6000).&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a basic guide to assembling a Pebble (Mk. 2) kit. In your kit, all the SMD components are pre-soldered on the board, the ATmega8U2 USB-to-serial circuit on the board has been pre-tested and the ATmega8U2 flashed appropriately, and the ATmega328 microcontroller has been pre-flashed with an appropriate Arduino Uno compatible bootloader.&lt;br /&gt;
&lt;br /&gt;
Now, let&#039;s start assembling the through-hole components on the board. Don&#039;t worry, it&#039;s all pretty easy to assemble.&lt;br /&gt;
&lt;br /&gt;
[[File:IMAG0615.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Kit Assembly (only the through-hole components)==&lt;br /&gt;
&lt;br /&gt;
=== Terminal Blocks, Electrolytic Capacitors, Trimpot===&lt;br /&gt;
&lt;br /&gt;
We will start by installing the 2-pin screw terminal block for the battery connection, in the upper left of the board. Make sure that the holes where the wires are inserted into the terminals face out towards the outside edge of the board. The sloped face need to face outwards. Next, we will also insert and solder the two 220 uF electrolytic capacitors in the upper left of the board. The capacitors are polarised, they need to be inserted into the board with the negative lead (the one marked with a stripe down the length of the capacitor body) inserted into the hole marked &amp;quot;-&amp;quot;, and the positive lead (which should be longer) inserted into the hole marked &amp;quot;+&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The 10uH inductor is a large round cotton reel shaped component. It is not polarised. You will find that you are not able to mount it flush with the board, so just push it down firmly until it won&#039;t go any lower.&lt;br /&gt;
&lt;br /&gt;
[[File:IMAG0619.jpg]]&lt;br /&gt;
&lt;br /&gt;
We will also fit the shorting jumper onto the two-pin header at this stage. &lt;br /&gt;
&lt;br /&gt;
The trimpot is used to adjust the LCD display contrast and is mounted in one way. Insert and solder the trimpot onto the board. It can only be inserted one way.&lt;br /&gt;
&lt;br /&gt;
[[File:IMAG0624.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Headers ===&lt;br /&gt;
&lt;br /&gt;
Insert and solder the two 6-pin ISP programming headers, which have 2 rows of three pins. The ISP programming headers make a very snug fit into their holes on the PCB, and you may need to use some sort of tool (The end of the handle of a screwdriver or cutters) to apply firm pressure to press these fully down into place.&lt;br /&gt;
&lt;br /&gt;
Insert and solder the 16-pin male header strip which connects to the LCD display.&lt;br /&gt;
&lt;br /&gt;
Insert and solder the pair of 8-pin female header strips and the pair of 6-pin female header strips that are used to mate with Arduino &amp;quot;shields&amp;quot;. The female headers don&#039;t always sit straight in the holes, so make sure you hold them straight while you solder just one of the pins to start with. Then you can adjust the alignment of the headers before soldering the rest of the pins.&lt;br /&gt;
&lt;br /&gt;
[[File:IMAG0628.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== RGB LED ===&lt;br /&gt;
&lt;br /&gt;
The RGB LED is a rounded, milky-coloured part with 4 long leads coming out one end.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note: The RGB LED must be inserted the correct way, with the flat side of the LED corresponding to the silkscreen marking. One of the LED pins is longer than the others, and one of the holes in the PCB has a square pad. The long lead goes into the square pad.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have any doubt about the orientation of the RGB LED please ask for help. Soldering it in only takes a moment, but getting it back out again can be extremely difficult!&lt;br /&gt;
&lt;br /&gt;
The four leads of the RGB LED will need to kind of splay out on an angle as you insert the LED onto the board, so it will end up sitting up approximately 5 mm off the board and it will not sit completely flush with the board. After ensuring that you have it oriented correctly, insert and solder in the RGB LED.&lt;br /&gt;
&lt;br /&gt;
=== DIP Socket ===&lt;br /&gt;
Insert and solder the 28-pin DIP socket for the AVR microcontroller.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The IC socket should be inserted so that the pin-1 indicator notch on the socket corresponds to the silkscreen marking, with the notch to the right if you&#039;re holding the PCB as shown below.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:IMAG0631.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== MCP9701 Temperature Sensor and 2N2222 Transistors ===&lt;br /&gt;
&lt;br /&gt;
In the bottom right hand corner you will find three semi-circular shapes on the silscreen, which are for one MCP9701 temperature sensors and two 2N2222 transistors. All three parts are in &amp;quot;TO-92&amp;quot; packages, and look absolutely identical.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Careful! Don&#039;t get them mixed up and put the parts in the wrong spots. They are not interchangeable.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The only way to tell them apart is by looking at the extremely small printing on the face of the part. If you have trouble reading them, don&#039;t guess. There are magnifying glasses at the front of the room.  To help ensure that you don&#039;t get them confused, it could be a good idea to separate out the MCP9701 and put the two P2N2222 transistors back in the bag or parts tray until you&#039;re ready to fit them.&lt;br /&gt;
&lt;br /&gt;
The MCP9701 is mounted facing the bottom edge near the mounting hole, in the location labelled &amp;quot;Temp&amp;quot;. Insert it and gently push it down until the body is about 5 to 8mm clear of the PCB. The leads will need to splay out a little to fit. Solder it in place carefully, doing each joint quickly and then letting the part cool down for a few seconds before doing the next one.&lt;br /&gt;
&lt;br /&gt;
Insert and solder the two transistors in the same way.&lt;br /&gt;
&lt;br /&gt;
==== Xbee Headers ====&lt;br /&gt;
It can be easier to hold the XBee header sockets in if you have an XBee module handy, by inserting the sockets onto the pins of the XBee module first and then inserting this assembly into the holes on the board. If you don&#039;t have an XBee module and don&#039;t intend to fit one, you can simply leave those headers off the board.&lt;br /&gt;
&lt;br /&gt;
=== Rotary Encoder===&lt;br /&gt;
Now we&#039;ll also insert and solder the rotary encoder. It should &amp;quot;snap&amp;quot; into place on the board as its mechanical mounting tabs are inserted into the PCB. The tabs can be tricky to clip in though and you need to be careful not to bend the thin leads while wrestling with the mounting tabs. You may find it helpful to get the part fully aligned and then use a tiny screwdriver or similar to push the tabs sideways until they clip in.&lt;br /&gt;
&lt;br /&gt;
=== LCD Module Header===&lt;br /&gt;
Unpack the LCD module and solder a 16-way pin male header onto its connection pads, with the header on the bottom of the PCB. The LCD connects to the Pebble via a ribbon cable (also supplied) so you can mount the display separately. When plugging them all together, make sure that pin 1 on the header on the PCB connects via the cable to pin 1 on the header on the LCD. One way to check is to hold the LCD directly over the PCB as if it was going to mount over the top of it, in which case the pins on the two sets of headers will naturally align correctly.&lt;br /&gt;
&lt;br /&gt;
=== ATmega328P Microcontroller ===&lt;br /&gt;
&#039;&#039;&#039;Warning: the MCU is a static-sensitive part. Minimise your handling of the pins once it has been removed from its protective anti-static foam.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The orientation of the MCU is critical. Pin 1 is noted by a notch at one end of the IC. It may be hidden by the sticker but should be revealed by pushing the sticker back a little. Ask if you are not sure. You will find that the legs of the IC may not line up correctly with holes in the socket. Please do not force it as that trick never works. Instead use a flat surface such as the workbench to push the legs in a little bit and then repeat for the other side. The trick is to be &amp;quot;firm, but not brutal&amp;quot; - it can take a reasonable amount of force to bend all the pins straight, but it&#039;s easy to overdo it and fold them over. Once again, please ask for help with this step if unsure.&lt;br /&gt;
&lt;br /&gt;
[[File:IMAG0638.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Testing===&lt;br /&gt;
&lt;br /&gt;
Plug in the USB cable (which we&#039;ve included for you) into a PC and into the Pebble board, and the blue power LED should light, and the new USB device should be recognized by the OS. If the power LED does not light, you &#039;&#039;&#039;did&#039;&#039;&#039; install the jumper to short out the USB power disconnection header, right? (Note that the power switch doesn&#039;t do anything except when battery power is used. If USB power is connected, then it is &amp;quot;always on&amp;quot;.)&lt;br /&gt;
&lt;br /&gt;
At this stage, you should be able to talk to the board from the PC. It&#039;s completely compatible with the Arduino Uno, but we re-used the same firmware used on the Freetronics Eleven, so it identifies itself as a Freetronics Eleven.&lt;br /&gt;
&lt;br /&gt;
If your PC is running Windows, you&#039;ll need to [http://www.freetronics.com/pages/installing-the-usb-driver-file-for-windows install the driver] if you&#039;ve never used an Arduino Uno or compatible device on your PC before. If you&#039;re running Linux or Mac OSX etc, then it should just work without any effort.&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also need to have the Arduino IDE installed, of course. Select &amp;quot;Arduino Uno&amp;quot; as the target hardware type, select the right (virtual) serial port for the Arduino IDE to talk to, and you should be all ready to upload programs.&lt;br /&gt;
&lt;br /&gt;
If you want to use the LCD, you’ll need to attach the LCD display. This is done by making sure that your LCD display has a 16-pin header soldered onto it, and connecting the 16-wire ribbon cable to both the LCD display and the LCD header on the main board, making sure that &#039;&#039;&#039;pin 1 on the Pebble board is connected to pin 1 on the LCD display&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
If you want test code, you can look at [http://marc.merlins.org/perso/arduino/post_2012-01-24_Much-Improved-Pebble-v2-Aiko-Demo-Code.html Marc MERLIN&#039;s page with a full test for most of the Pebble v2&#039;s hardware] (note the few example standalone programs that do not use Aiko at the end of that page, and hosted on https://github.com/marcmerlin/pebble_v2_demos )&lt;br /&gt;
&lt;br /&gt;
===Hardware Features===&lt;br /&gt;
&lt;br /&gt;
* Arduino Uno compatible, with ATmega328 and ATmega8U2 carrying the appropriate bootloaders.&lt;br /&gt;
* Boost-converter power supply for portable battery operation at battery voltages between 2.4-4.5 volts.&lt;br /&gt;
* RGB LED with each of the 3 LEDs independently programmable, including PWM capability.&lt;br /&gt;
* Standard HD44780 20x4 alphanumeric LCD display.&lt;br /&gt;
* Support for a low cost Nintendo DS style 4-wire resistive touchscreen.&lt;br /&gt;
* Support for an XBee 802.15.4 radio module or any other &amp;quot;Bee&amp;quot;-compatible module that operates at 3.3V and talks to a serial UART.&lt;br /&gt;
* Two general-purpose open-collector low-side-switching output transistors for controlling external devices such as relays.&lt;br /&gt;
* Rotary encoder for user input.&lt;br /&gt;
* Temperature sensor (MCP9701) and light sensor (TEMT6000).&lt;br /&gt;
&lt;br /&gt;
===Battery power===&lt;br /&gt;
&lt;br /&gt;
Now, if you want to use portable power without just being limited to USB use, let’s look at power options.&lt;br /&gt;
&lt;br /&gt;
After you&#039;ve programmed the board with some code, if you want to use an alternative power source away from your PC, you can either use battery power or you can provide regulated 5.0 V DC power to the USB socket via a standard USB cable - for example by using one of those common 5.0V mains switchmode plugpacks with a &amp;quot;dumb&amp;quot; USB connector for power output.&lt;br /&gt;
&lt;br /&gt;
The battery voltage input must be within the range of about 2.4 - 4.5 V for correct operation. &#039;&#039;&#039;Thou shall not ever exceed 5 volts&#039;&#039;&#039;, into either of the power supply inputs, on this device.&lt;br /&gt;
&lt;br /&gt;
You can use two standard alkaline or NiCd or NiMH cells in series, for a voltage supply of 3.0 V (or 2.4 V if you’re using 1.2 V NiMH cells), or you can use 3.6-4.5 V from a set of three cells in series. The latter will provide an improvement in battery life. The 2.4 V you will get from two NiMH cells is OK, but it is towards the lower end of the operational voltage window.&lt;br /&gt;
&lt;br /&gt;
You can use common “AA” or “AAA” cells, however the larger types such as “C” or “D” cells will provide greater charge capacity and a greater runtime. You could also use a 3.7 V lithium-polymer cell, where a small, lightweight battery with high energy density is desired. (Note that there is no battery holder included with the kit and you can add your own separately if you want to use battery power.)&lt;br /&gt;
&lt;br /&gt;
Make sure that the positive and negative wires from the battery holder are connected to the terminal block on the board with the correct polarity, as marked on the silkscreen, and ensure that charged batteries are inserted into the battery holder with the correct polarity. With the batteries installed and wired up, you should then be able to turn on the power switch on the board, and the power LED should light up. (The on-board power switch has no effect if USB power is connected.) If you’re using a battery holder which has a built-in power switch then this power switch must also be turned on.&lt;br /&gt;
&lt;br /&gt;
There is no battery charging electronics built into the device - to recharge your batteries they must be disconnected and recharged externally.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Semi-permanent solder jumpers===&lt;br /&gt;
&lt;br /&gt;
SJ1 is normally closed, this is for automatic reset of the AVR, controlled by the USB UART interface, during programming. Cut it to disable auto-reset.&amp;lt;br&amp;gt;&lt;br /&gt;
SJ2 connects the USB shield to ground. This is normally closed and should never normally need to be opened.&amp;lt;br&amp;gt;&lt;br /&gt;
SJ3 is normally open. This is for the DFU programming of the ATmega16U2 and should never need to be closed.&amp;lt;br&amp;gt;&lt;br /&gt;
SJ4 is normally closed, and this connects the high side of the two low-side-switching open collector output transistors to +5V. Disconnect it if you want to use an external higher-voltage power supply for these circuits.&lt;/div&gt;</summary>
		<author><name>Marcmerlin</name></author>
	</entry>
</feed>