Difference between revisions of "Swagbadge2021 Newcomers"
(→Electronic circuits) |
(→Electronic circuits) |
||
(5 intermediate revisions by the same user not shown) | |||
Line 89: | Line 89: | ||
[[File:Lolin32_lite_schematic.gif|480px]] | [[File:Lolin32_lite_schematic.gif|480px]] | ||
− | In order for components to work, they need a power source (typically for the SwagBadge that's a USB cable providing 5 volts [https://en.wikipedia.org/wiki/Direct_current direct-current]), they need a [https://en.wikipedia.org/wiki/Ground_(electricity) ground] (also on the board), and the | + | In order for components to work, they need a power source (typically for the SwagBadge that's a USB cable providing 5 volts [https://en.wikipedia.org/wiki/Direct_current direct-current]), they need a [https://en.wikipedia.org/wiki/Ground_(electricity) ground] (also on the board), and the components sit between the power and the ground. But you can't just plug in any old component into any old power source. Things can go wrong: |
* Too much power for a component can fry it and let out the [https://en.wikipedia.org/wiki/Magic_smoke magic smoke]. | * Too much power for a component can fry it and let out the [https://en.wikipedia.org/wiki/Magic_smoke magic smoke]. | ||
* Not enough power and your component just won't work. In an attempt to get enough power, it may even fry your badge's power source - if it's powered via USB to your laptop, this may mean doing Bad Things to your USB port or your laptop. | * Not enough power and your component just won't work. In an attempt to get enough power, it may even fry your badge's power source - if it's powered via USB to your laptop, this may mean doing Bad Things to your USB port or your laptop. | ||
− | |||
− | |||
Whilst the USB cable provides 5 volts (and an optional LiPo battery provides around 3.7 volts), everything (including the SAOs) beyond the USB cable and voltage regulator is '''powered by 3.3 volts'''. Many of the components may be damaged by exposing them to greater than 3.6 volts (3.3 volt rating plus 10%). It is also very important to not accidentally swap power and ground (connect ground to the power lines and the power to the ground lines), which may also damage components. | Whilst the USB cable provides 5 volts (and an optional LiPo battery provides around 3.7 volts), everything (including the SAOs) beyond the USB cable and voltage regulator is '''powered by 3.3 volts'''. Many of the components may be damaged by exposing them to greater than 3.6 volts (3.3 volt rating plus 10%). It is also very important to not accidentally swap power and ground (connect ground to the power lines and the power to the ground lines), which may also damage components. | ||
The role of the voltage regulator is to reduce the power supply voltage (from 5 volts) to the 3.3 volts required by the SwagBadge circuitry and components. Looking closely at the schematic diagram at '''''U4: ME6211''''' (top, middle), you can see that the inputs are <VBUS> (USB cable power), <VBAT> (LiPo battery power) and <GND> (the ground) ... and that the outputs are <+3V3> (3.3 volts) and <GND> (not strictly an output, but for the sake of modularity, let's pretend). Throughout the schematic, many components have an "arrow" pointing towards <+3V3>, which simply means "connected to", in this schematic diagram the arrow does not indicate "flow of elections" or anything like that. | The role of the voltage regulator is to reduce the power supply voltage (from 5 volts) to the 3.3 volts required by the SwagBadge circuitry and components. Looking closely at the schematic diagram at '''''U4: ME6211''''' (top, middle), you can see that the inputs are <VBUS> (USB cable power), <VBAT> (LiPo battery power) and <GND> (the ground) ... and that the outputs are <+3V3> (3.3 volts) and <GND> (not strictly an output, but for the sake of modularity, let's pretend). Throughout the schematic, many components have an "arrow" pointing towards <+3V3>, which simply means "connected to", in this schematic diagram the arrow does not indicate "flow of elections" or anything like that. | ||
+ | |||
+ | You can think of electronics components as analogous to software functions ... there are input(s), output(s) and some shenanigans occur in-between ! This is great, because you can largely forget about the whole SwagBadge circuit and focus on just the SAO connector's inputs and outputs, e.g 3.3V power, ground, I2C (clock and data pins) and two General Purpose Input / Output (GPIO) pins. Too easy ! | ||
'''Getting the power requirements right''' | '''Getting the power requirements right''' | ||
Line 123: | Line 123: | ||
Note: Often the eThingy will have a voltage potential across them too, reducing the voltage potential across the resistor in the calculation above. See LEDs below | Note: Often the eThingy will have a voltage potential across them too, reducing the voltage potential across the resistor in the calculation above. See LEDs below | ||
− | Usually, the resistor can be placed on either side of the component ... either between power and the component ... or the ground and the component. In either case, the resistor is limiting the current flow just fine. | + | Usually, the resistor can be placed on either side of the component ... either between power and the component ... or the ground and the component. In either case, the resistor is limiting the current flow just fine. However, to keep things simple and consistent, it is recommended to make the "ground" our shared base for everything and achieve this by putting the current limiting resistor between power and the component. |
'''LEDs are special, because they do not act like pure resistors''' | '''LEDs are special, because they do not act like pure resistors''' | ||
LEDs have complicated behavior that affects our use of Ohm's Law, so we have to do a bit more to get the values right. For LEDs, the important thing is the voltage drop across the LED. This can also be known as the forward voltage. | LEDs have complicated behavior that affects our use of Ohm's Law, so we have to do a bit more to get the values right. For LEDs, the important thing is the voltage drop across the LED. This can also be known as the forward voltage. | ||
− | * | + | * LEDs have static resistance and our circuit will still obey R = V / I, but let's adjust for how we calculate the current limiting requirements for an LED as follows: Required resistor = (Power voltage - LED voltage drop) / Desired maximum current |
Quick example: | Quick example: | ||
Line 141: | Line 141: | ||
'''More about resistors''' | '''More about resistors''' | ||
− | Resistors come in certain set values. If you can't get the exact value you need, just use the next highest one (don't go lower, or your resistor won't do the job and you'll fry your electronics). You can [https://www.electronics-tutorials.ws/resistor/res_3.html join them together in series] if you want to create a larger resistance (works just like a single resistor | + | Resistors come in certain set values. If you can't get the exact value you need, just use the next highest one (don't go lower, or your resistor won't do the job and you'll fry your electronics). You can [https://www.electronics-tutorials.ws/resistor/res_3.html join them together in series] if you want to create a larger resistance (works just like a single resistor of the equivalent value). You can [https://www.electronics-tutorials.ws/resistor/res_4.html join them together in parallel] if you want to create a smaller resistance (also works just like a single resistor of the equivalent value). |
[https://www.electronics-tutorials.ws/resistor/res_1.html Everything you wanted to know about resistors, but were afraid to ask !] | [https://www.electronics-tutorials.ws/resistor/res_1.html Everything you wanted to know about resistors, but were afraid to ask !] |
Latest revision as of 05:34, 6 February 2021
Contents
Swagbadge for newcomers to electronics
Welcome! 👋
This guide is for everyone who likes the sound of what the swagbadge can do, or have an interest in learning about some hardware and electronics but just doesn't know where to start, or wants to learn as part of a community. We are here for you! This guide is intended to help you learn, through the development of the Swagbadge or Dagbadge. It (will) have lots of pointers out to resources on the internet you can use for further reference and learning.
Contents:
- What is a Swagbadge or a Dagbadge?
- The components on the badge
- Some electronics fundamentals
- Software makes the hardware go
- The Aiko framework
- Applications
- All about SAO - Simple Add Ons
What is a Swagbadge or a Dagbadge?
A swagbadge is the officially branded, fully pre-assembled electronic badge provided to early registrants to LCA 2021. Designed to work alongside the standard paper badge normally provided to participants, it provides a talking point, an access to hardware and electronics, and their corresponding software, and is extensible both now and into the future.
For those who can't get hold of a swagbadge (you registered too late to LCA 2021, you're attending LCA but don't live in Australia, or you're just interested in the process and want to be part of our wider community), there's the dagbadge. This is a list of parts that you acquire yourself (without the LCA branding), designed to be readily obtained from your local or online electronic store. You need to assemble it yourself.
The components on the badge
The swagbadge contains:
- a PCB
- a Lolin32 ESP32 microprocessor
- two OLED screens
- two switches
- two capacitive touch slider controls
- four SAO headers
For the list of parts on a dagbadge, see Dagbadge BOM, but it is essentially the same, but with a breadboard instead of a PCB.
What do all those elements mean?
Imagine that the badge is a creature.
- the Lolin32 ESP32 microprocessor is the brain. It is a tiny computer, designed for embedded/IoT applications, of a type called a ESP32, manufactured to the Lolin32 standard (first built by the WEMOS company but frequently copied). It has:
- Wifi
- Bluetooth
- 4Mb (?) of flash memory
- Low power consumption for long life when battery powered
- Powered by microUSB - USB, but is capable of handling an external battery if you know how to connect it.
- the PCB is a Printed Circuit Board. It is combination skeleton and nervous system. Like a skeleton, it holds the other parts in place. Like the nervous system, it contains circuitry printed on it to let the microprocessor (the brain) communicate with all its senses, and talk to other devices.
- the two OLED screens are like inverse eyes. They are tiny computer screens, supporting black and white text, pixel and lines display, at a resolution of 128x64 (?). We have provided two so you can use them as one super wide screen, or as two separate screens.
- the two switches are underneath the screens on the swagbadge. Push the screen and it pushes the switch. The software can read the hardware to detect which switch is being pressed, and whether it's a single press or a long press.
- the two capacitive touch slider controls are sensors. As you move your finger up and down the lines, the software can read the hardware to find out (roughly) where your finger is on which slider. They're called "capacitive" because that is the mechanism by which the component works: it uses the capacitance in the circuit, affected by your finger, to tell where you're touching. Your smartphone's screen operates via capacitive touch..
- the four SAO headers are Simple Add On headers, which let you extend the capability of your badge with other components and boards using the SAO standard - there'll be a dedicated Swagbadge SAO wiki page soon(tm).
Some electronics fundamentals
- Extra pins on the board.
- Do not immerse in water/tea
- ... I'm sure I had more to add here.
Software makes the hardware go
The hardware on its own is inert. It doesn't do anything without something to read the sensors, or display information on the screen. So what drives the badge?
- Operating system: the Swagbadge uses MicroPython, a special version of the Python programming language designed for use on small internet of things/embedded devices, just like the badge.
- A framework. This is Aiko for MicroPython, written by Andy Gelme of the Open Hardware team. It provides a whole bunch of convenience functions for writing to the screens, or reading the value of switches. It's also designed to make communicating to a badge over a network a lot easier by providing access to the badge's capabilities via sending simple messages to the badge via an MQTT server. We are using a dedicated MQTT server for the badges, based in Australia so it's nice and fast!
- Applications. Written in MicroPython, these are programs to make your badge do things! Several are provided, to demonstrate some capabilities to help you learn how to use the badge and copy as required to make your own code work.
The Aiko Framework
Applications
All about SAOs: Simple Add Ons
The swagbadge came with several SAO protoboards. Our SAO prototyping boards come with standard sized holes in them to make it easier to mount components such as LEDs if you didn't have a custom SAO from Tindie or that you'd built yourself, and they have labelling on them so you can see which holes are for power or ground or are connected to the GPIO pin (this being the pin that controls a component).
Why use a protoboard instead of wiring things directly onto the badge?
- You can remove the board, if you want to reposition your SAO, or swap it for something else
- It's an easier base for adding multiple components
Electronic circuits
Itching to add some blinky lights to a SAO ... by whipping out that soldering iron and getting to work ? Let's first talk about circuitry.
It is very difficult to think about, design, repair or discuss something unless you have a clear picture (model) in your mind. This is especially true of electronics, because without tools (a simple LED, multimeter, oscilloscope, logic analyzer or scanning tunneling microscope) we just can't see electrons. Knowing how the electrons flow through circuits within your SwagBadge is one of the crucial keys to understanding. Fortunately, you can approach this problem in simple steps ... well, "simple" if you have good guidance. Please feel free to ask the OHMC team on the SwagBadge Spectrum forum !
<ToDo: Start with high-level diagram before diving in deeper !>
Let's dive in the deep end by briefly checking out a schematic diagram (pictured below). There are lots of unfamiliar symbols and terminology, but in essence it is like a map. A map that shows what components exist in the circuit and how they are connected together, from which we can determine how electricity (electrons) flows to encode data and changes to that data.
Note: The voltage regulator discussed soon is in the top-middle of the diagram with a part labelled U4: ME6211
In order for components to work, they need a power source (typically for the SwagBadge that's a USB cable providing 5 volts direct-current), they need a ground (also on the board), and the components sit between the power and the ground. But you can't just plug in any old component into any old power source. Things can go wrong:
- Too much power for a component can fry it and let out the magic smoke.
- Not enough power and your component just won't work. In an attempt to get enough power, it may even fry your badge's power source - if it's powered via USB to your laptop, this may mean doing Bad Things to your USB port or your laptop.
Whilst the USB cable provides 5 volts (and an optional LiPo battery provides around 3.7 volts), everything (including the SAOs) beyond the USB cable and voltage regulator is powered by 3.3 volts. Many of the components may be damaged by exposing them to greater than 3.6 volts (3.3 volt rating plus 10%). It is also very important to not accidentally swap power and ground (connect ground to the power lines and the power to the ground lines), which may also damage components.
The role of the voltage regulator is to reduce the power supply voltage (from 5 volts) to the 3.3 volts required by the SwagBadge circuitry and components. Looking closely at the schematic diagram at U4: ME6211 (top, middle), you can see that the inputs are <VBUS> (USB cable power), <VBAT> (LiPo battery power) and <GND> (the ground) ... and that the outputs are <+3V3> (3.3 volts) and <GND> (not strictly an output, but for the sake of modularity, let's pretend). Throughout the schematic, many components have an "arrow" pointing towards <+3V3>, which simply means "connected to", in this schematic diagram the arrow does not indicate "flow of elections" or anything like that.
You can think of electronics components as analogous to software functions ... there are input(s), output(s) and some shenanigans occur in-between ! This is great, because you can largely forget about the whole SwagBadge circuit and focus on just the SAO connector's inputs and outputs, e.g 3.3V power, ground, I2C (clock and data pins) and two General Purpose Input / Output (GPIO) pins. Too easy !
Getting the power requirements right
- Work out what the power consumption requirements are for your components, for both voltage and current
- If it's more than what your power source provides, you'd better get a bigger power source/battery and hook up the power to that, and not to the badge
- If it's less than what your power source provides, you'll need some resistors* to reduce the load going through your components
Note: Using resistors works for passive components, however some active components may need a different approach to limiting current through them
It's just maths
Ohm's Law is our guide. V = I x R. Voltage (V) = Current in amps (I) x Resistance in ohms (R).
We know our badge gives you 3.3V
You can determine the current requirements of your components by looking at their data sheets. Some will have a maximum current rating (you must stay below this !) and a recommended current rating (what you're aiming to meet).
Quick example:
- Let's say you have an eThingy that has a recommended current rating of 20 milliamps
- Voltage off the badge is 3.3V
- We use Ohm's Law to calculate the resistance (R = V / I), in our case, V = 3.3, I = 0.02 ... so R = 3.3 / 0.02 = 165
- We need to use a 165 ohm resistor
Note: Often the eThingy will have a voltage potential across them too, reducing the voltage potential across the resistor in the calculation above. See LEDs below
Usually, the resistor can be placed on either side of the component ... either between power and the component ... or the ground and the component. In either case, the resistor is limiting the current flow just fine. However, to keep things simple and consistent, it is recommended to make the "ground" our shared base for everything and achieve this by putting the current limiting resistor between power and the component.
LEDs are special, because they do not act like pure resistors
LEDs have complicated behavior that affects our use of Ohm's Law, so we have to do a bit more to get the values right. For LEDs, the important thing is the voltage drop across the LED. This can also be known as the forward voltage.
- LEDs have static resistance and our circuit will still obey R = V / I, but let's adjust for how we calculate the current limiting requirements for an LED as follows: Required resistor = (Power voltage - LED voltage drop) / Desired maximum current
Quick example:
- If you have a red LED with a voltage drop/forward voltage of 2V, and maximum current requirement of 20 mA (milliamps)
- Power voltage on the badge is 3.3V
- R = (3.3 - 2) / .02 = 65
- We need a 65 ohm resistor
- A 65 ohm resistor will provide maximum brightness and larger resistor values, e.g 1,000 ohms will limit the current further and delivery a dimmer LED experience
Note: Different colour LEDs will have different forward voltage drops. For a given colour, e.g red, there will be a small range of forward voltage drops, e.g 1.7V to 2.0V.
More about resistors
Resistors come in certain set values. If you can't get the exact value you need, just use the next highest one (don't go lower, or your resistor won't do the job and you'll fry your electronics). You can join them together in series if you want to create a larger resistance (works just like a single resistor of the equivalent value). You can join them together in parallel if you want to create a smaller resistance (also works just like a single resistor of the equivalent value).
Everything you wanted to know about resistors, but were afraid to ask !
Series vs parallel
Up until now, this tutorial has assumed you've just been powering a single thing. But what if you want to do multiple? More lights are better lights, after all! There's two different ways to connect components together: in series, or in parallel.
- series
- they're chained together, one after the other on a single loop from power, through the components and onto ground.
- parallel
- there's multiple circuits, each one connected separately to the battery