Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Avionics uses Trello for project management
Probably best said by Trello itself.
Trello is a project management software which allows us to track tasks which need to be done, what stage projects are in, and what everyone is working on. It helps streamline our workflow by making sure we always know what we have done, what we are doing, and what we have left to do.
Create a Trello account and message the Avionics lead to gain access to the above Trello team for Avionics.
Getting started with the development environment for the Avionics codebase
The Container Environment section will go over setting up the tools for compiling firmware, the Writing and Compiling Firmware section will go over compiling the firmware, and the Flashing Programs to the Microcontroller section will go over writing compiled code to hardware.
Avionics distributes a container which contains all the tools for compiling our firmware. Some of the development tools we use for firmware development are a mild pain to install (particularly for beginners), so using the container is recommended for quick set up.
If you have tried out the container and have problems given your setup, and you really want to install yourself, go ahead. This is not recommended unless you are well acquainted with installation of compilers, etc.
To use the container environment, you will need to install the Docker or Podman first. Podman is the fully open source alternative to Docker, and they share the same commands format. Either can be used, although most of this tutorial will use Podman because it is easier to use on Windows.
If on Linux, there's too much variety to put anything here. I'm sure someone in avionics will want to help! Podman is very easy to use on Fedora and works out of the box.
If on Mac, this is all currently untested.
On Windows, you the recommended procedure is to install Windows Subsystem for Linux (WSL) and run Podman within it.
Since WSL is a non-standard linux environment that lacks of some important syscalls and processes, Docker cannot be run on WSL without some hassles. Podman has been tested on WSL, and you should follows the instruction below.
If your Windows 10 is Home version, you might not be able to enable Hyper-V. You should upgrade to Windows 10 Pro, or just use the free educational version from the school: https://software.berkeley.edu/microsoft-operating-system
Follow the instruction on https://docs.microsoft.com/en-us/windows/wsl/install-win10. You should install WSL 2. This tutorial is based on OpenSUSE, but it is possible to use other distros.
Once you finish, install Podman by running
Then, run the following instruction to create and modify the config file to make it run on WSL:
Then, use an editor of your choice, open /etc/containers/containers.conf
with sudo
:
Uncomment the line with events_logger
, then change the value to file
.
Uncomment the line with cgroup-manager
, then change the value to cgroupfs
.
You should be able to run the docker file right now. Note that you must run Podman with sudo
, or you won't be able to do anything. If you are getting No CNI Configuration file
error, do the following steps:
Run sudo podman network create
. It should give you a filename.
In the command you used to run docker, add --net <config-name>
after podman run
. <config-name>
is the filename you got from the first step.
The toolchains repo here has a readme with additonal information about the development environment.
First download the toolchain container image.
Then, create a directory where the files in the container will be stored.
The location of this directory can be viewed with :
Finally, create the container
Once the container is setup, it can be started with:
You can enter the toolbox to a bash
prompt with the below. This is where you will be actually running commands to use the compiler, etc.
Finally, once the container bash prompt is exited with exit
, the container can be stopped with
An alternate way to transfer files is using the Visual Studio Code editor. This may be convenient if you already use VS Code, and may be a method that works if this does not. See the VS Code & Containers
section.
To copy a file from the image to the host system (your normal operating system), you need to first get the mount point of your workspace by running
where star-workspace
is the volume name. If you use another volume name, you need to change the command accordingly. You can save it to a environment variable to avoid copying the long path every time.
Since the path is usually only accessible with root privilege, you need to copy it to a place that you can access without sudo
, like your home directory:
Then, if on Windows, open Windows Explorer, type in \\wsl$
in address bar. For every distros you install, you can see a folder with the same name as the distros in this folder. Go to the distro folder that you use to run Podman, and go to the path you copy the file to in the last step, like home/<user-name>
. You should be able to see the file you want in that directory, and you can copy and paste it to anywhere you want in your Windows file system.
If not on Windows, simply open a terminal and go to ~
. The file will be there.
To setup, install the Remote Containers extension in VS Code.
Then, go to the "Remote Explorer" tab on the left bar of VS Code, right click on the container you created in the previous step and click attach to start a VS Code instance in the container. From here you should be able to open a terminal inside the container by going to Terminal->New Terminal
and interact with the filesystem through VS Code and clone stuff, open folders, etc.
In this section we detail how to compile code into binaries which can be written onto the hardware.
'Firmware' is the code which runs on the hardware, named so because it is 'closer to the hardware' than normal desktop software.
We use MbedOS for libraries and a lot of the support code needed. The tools needed to run mbed are all included in the container. Run the commands below from the container prompt.
For most cases, you will only need the Developing STAR firmware projects section.
For documentation on the Mbed API, look at the official docs here. If you don't find a library for what you want there, look at community built libraries by searching using the search box in the upper right corner.
For more detailed documentation on Mbed Command Line Interface (CLI), look at the official docs here.
While the mbed utilities can be used directly, most often in STAR we iterate on existing STAR projects. Therefore we have abstracted away most of the mbed commands using Makefiles. Note that the specific build system can vary slightly from git repository (repo) to repository, so make sure to check the Readme of the specific project you are working on.
If you are unfamiliar with the Git version control system, check the Git Tutorial out before continuing.
First clone the desired repository from within the container, e.g.
Then from within the repository, clone the submodules and run mbed deploy
Finally, compile with a command like
Check the repository Readme for details on the command to run to compile. The output, the binaries to flash to the microcontroller, will be put in the output
folder.
To create a new project called mbed_project
, run the following:
To compile a project, run the following from within the project folder
The target, NUCLEO_F401RE
is a development board that has the STM32F401RET6
microcontroller on board, the same microcontroller unit (MCU) that we use. The toolchain selects which compiler we are using.
This should give you something like the following if it compiled successfully.
Find libraries by searching in the search bar on mbed's website. Then, once on a library's page, look at the box titled "Repository toolbox" and select the down arrow on the yellow "Import into Compiler" button.
Then select "Import with mbed CLI" and copy the command listed.
The command should be of the form mbed add <project link>
. Run this command from command line inside your mbed project.
'Flashing' a program onto a microcontroller means to write the compiled code onto the microcontroller to be run when the microcontroller is powered off and back on.
As of right now, usb-detection and programming through the container is not working. Instead install and use a utility on the host system.
Windows: Download and install the St-Link Utility from the file below. To use, first File > Open file
the binary of the program output by mbed compile
. Then Target > Connect
to the board, and Target > Program & Verify
Linux: Install the stlink package from the package manager if available or compile from source here.
To use, open stlink-gui and perform similar steps to the windows version to flash.
Alternatively, use st-info --probe
to search for programmers and st-flash write $binary_output_file 0x8000000
to flash.
Installing and using KiCAD for editing schematics, layouts, symbols, and footprints.
Download KiCad from here:
This also contains instructions for each system.
The KiCad tutorial is actually pretty good, so in general refer to it. The Avionics intro project (on Gitbooks) guide also walks through usage of KiCad.
Use the following link to learn how to make new symbols for components when you can't find an existing symbol for it in the KiCad libraries.
Often, it can be worth finding an existing symbol that is similar (for example, an older version of a sensor), copying it, and modifying it.
Try to make symbols following a functional pattern of placing pins. Symbols don't need to look like the footprint of an IC. Often, symbols of ICs will have all Vdds/Vccs/Vddios at the top, all Vss's at the bottom, and pins on the sides of the symbol.
STAR has has a repository hardware-sch-blocks
which contains a library of symbols, star-common-lib
. Create your symbols in this repository on a new branch, add them to the library, and when ready submit a pull-request. Make sure to update the datasheet link and description!
As with schematic symbols, try finding an existing footprint and then modifying it according to the actual component's datasheet. Datasheets will have drawings and dimensions of the footprint, often under a section such as 'Packaging'.
Many ICs come in standard packages (such as SOT-8). KiCad includes footprints for these standard packages, so often one can select one of these and then ensure with the datasheet that it matches--unfortunately, different manufacturers may use the same name but actually have slightly different footprints.
As with symbols, all STAR footprints go in star-common-lib
in hardware-sch-blocks
. Create your footprints on a new branch (makes sense to put them on the same branch as the new symbols), and submit a pull-request. Please let the current Avionics lead know when you submit a pull-request so it doesn't slip through their email.
How to design a schematic and layout for PCBs
Some parts of this page may be out of date (in particular, the section "Before You Submit"). The rest of this page is a great reference!
Please note that there is a board design DeCal that can give you a more detailed understanding of how to build PCBs: . Though this tutorial will follow the format of the decal's , this page is just an introduction. You can access the syllabus and material at this link: . Here is another useful resource on PCB design: h
Board design "useful tips" document from the aforementioned board design decal:
A printed circuit board, or PCB, is the backbone of hardware design. These cheap, compact, reliable boards allow us to implement circuits into a greater system. They are better than alternatives in that they provide form (hold everything together) and function (make good electrical connections). They are built from conductive copper layers separated with non-conductive substrates and include things called vias, tracks, and pads which will be discussed later. While the process of making PCBs may seem long and frustrating, this tutorial will guide you through the most basic parts of making a good PCB.
In order to start making your PCB, you will need a design. It should meet your system specifications under all relevant conditions (such as temperature or vibration) in little time for little cost with few iterations (don't worry if you have to redo your design, but don't just guess and check). Your design should be testable and fail minimally. You can start a design by identifying what particular electrical components provide which functions. These components are then put into something called a schematic, which essentially pieces these components together to make your design work.
Before starting anything else, make a . This should outline exactly what you want your board to do, but should not specify implementation details. For example, a telemetry and power control board might be expected to transmit and receive data at 96 kBits/s, provide up to 500 mA at 5V for 6 hours, etc. Each of these desired functions should be testable before final deployment of the system (i.e. a function like "doesn't run out of power on the pad if there's a delay" would be better written as "provides up to 500 mA at 5V for 6 hours").
Your specification document should be roughly 0.5-2 pages long, depending on the complexity of the project. You may refer to a higher-level system architecture document, or even omit the specification document and simply use a section of a system architecture document as your spec, depending on how far design work has progressed. Make sure to also refer to the rules and regulations of whatever competition the board is for (); explicitly citing these in a spec document is always good.
Once you have your functionality decided upon, it's time to start developing the design a little further. At this stage, continue updating your specification document or create a new system architecture document that will contain all design choices to achieve the desired functionality.
This is where questions like "do we need a microcontroller or can this be done without one?" or "how are we going to power this board?" should be answered. As you do this, feel free to update your specification document as you realize what additional functionality is needed. At this stage, you should also consider exactly how your board may interface with other devices and people (radio, serial communication, LEDs to communicate power/status, switches, etc.)
Depending on your familiarity with the available hardware, you may not be able to fully specify the architecture before taking a look at the next section, Selecting Parts. It is perfectly fine to go back and forth between looking at available components and updating the system architecture.
Selecting parts to use for your design may seem like a tedious task, but it's extremely important to get right for your project to work. After determining your desired functionality and architecture, you know what passive component values and ICs (integrated circuits) you will need, but that is only a small part of selecting the physical part that will end up on your physical board. Here are some things to consider:
Components come in may different sizes and shapes: some are larger, some are smaller, some are impossible to solder, etc. It is extremely important to pick a correct form factor for each component, or your design will be impossible to assemble.
Solderability
How small is the component? For passives, CalSTAR uses 0603 Imperial or larger.
Does it have leads or is it marked QFN (no leads) or BGA (ball grid array - under the IC)? If the latter, you will need a reflow oven and cannot solder by hand. If absolutely necessary, QFN/LGA components may be solderable at a hot-air station; ask a subteam or project lead if you think this might be necessary.
Surface Mount vs. Through-Hole
Surface Mount (SMT/SMD) and Through-Hole (THT or DIP) are two forms the component can take. The former lies flush on the board and are usually smaller while the latter is put in a hole through the board.
Passives and ICs should be SMD, while connectors are usually through-hole. The more compact the board, the better.
When looking at an IC's application circuit schematic/layout, consider the complexity and the sensibility of the externals required. If it is not appropriate for your design, consider another IC. Many ICs require an extensive network of resistors, capacitors, etc. to function properly.
In general, while searching for parts, whether from Digikey (preferred) or Mouser or Adafruit, read the datasheet and specs carefully to ensure they fulfill the requirements you need. You need to check that is can drive the correct load, provide or handle enough current, is powered by the correct voltage, is the right size, and for passives, is the right value. Here is an example of a search for a specific 10kOhm 0603 SMD resistor from Digikey:
Microcontrollers are essentially the "brain" of the PCB. You can program them to perform specific tasks (for example, light up an LED or interpret sensor data). They are usually quite complex and have dedicated pins for their different functions. GPIO pins (General Purpose Input-Output) are especially useful for customization. CalSTAR has previously used AVR processors by Atmel (ATmegas, the same as commonly found on Arduinos), but we are now using 32-bit ARM chips made by STMicroelectronics (STM32F401RET6, for example).
Transistors are three-terminal semiconductor devices used to amplify or switch electronic signals and electrical power. There are many different types of transistors, but the most common that you'll see are BJTs (bipolar junction transistors) and (MOS)FETs, which are (metal-oxide semiconductor) field effect transistors. Transistor physics is generally not covered well in lower-division EE classes; feel free to ask someone for help picking a transistor if you're unsure.
DC-DC converters converts one DC voltage into another. For example, a 12-V battery voltage may need to be stepped down to 5 or 3.3V. There are two common types: LDO and switching regulator. The LDO (linear drop-off) is generally simpler to implement into a PCB because it has fewer external components, but it uses a lot of power.
Passive elements include resistors, capacitors, inductors, oscillators, buzzers: anything that either consumes but does not produce energy or that is incapable of power gain (unlike a transistor that is capable of amplifying). Capacitors and inductors can used for oscillation (like a voltage regulator). Capacitors can also be used for coupling/decoupling.
These are usually LEDs or buzzers: anything that indicates a specific function is occurring. LED's are important to indicate whether power is being supplied to a PCB, for cases of safety and debugging. Buzzers can be used when the PCB is obscured (like in the rocket) and the board LED is no longer visible. Small green SMD LEDs are common to indicate power, while other colors can be used to indicate activity or danger.
A diode is an semiconductor device with two terminals that allows for the flow of current in one direction only. An LED (light emitting diode) is one example. Diodes can be used for reverse polarity protection, i.e. if you connect power in the wrong direction, current will not flow and therefore will protect your circuit. Zener diodes can also protect surges by having one terminal connected to a power net and one connected to ground.
A fuse is a safety device that prevents a short circuit from damaging the rest of the board. There are two types: resettable and non-resettable fuses. A non-resettable fuse works by allowing the overcurrent to melt a small piece of metal in between its terminals so that it becomes open. A resettable fuse has a material in between its terminals that, instead of melting, increases resistance and cuts off current flow.
These are the components that are usually soldered to the edge of the board that allow it to connect to the necessary peripherals. For example, a battery will need a connector (usually an Anderson PowerPole), while screw terminals may be used for wire connection to other PCBs.
There are many different ICs (integrated circuits) that your PCB may need in order to function. This includes sensors (like a GPS, altimeter, accelerometer, or gyroscope) to provide information about what your project is doing (in our case, what is happening during flight). In addition, a radio IC, with attached antenna, is useful for communicating commands to the microcontroller during testing and flight.
While selecting your parts, you will need to write them down. Each component requires a lot of information in order to purchase the correct one. Here is an example BOM, with the necessary columns:
The manufacturer part number is the number of the manufacturer (for example, Infineon) of the component while the supplier part number is the code of the supplier (for example, Digikey). "Ref Des" stands for Reference Designator, which is the number of the component in your schematic. Make sure that you select the correct size for all components and that their packages are appropriate for your layout. For example, make sure resistors/capacitors are 0603 and that you distinguish between through-hole and surface mount.
What is a schematic? They are drawings that represent elements in a system using abstract symbols to give information without unnecessary details. You can implement these schematics in your PCB design software, as discussed in the information notes at the top of this page. In general, signals should go from left to right, top to bottom, with higher voltages at the top and lower at the bottom. Here is an example in KiCad (the long parallel gray lines are to indicate the separation of functions in the circuit):
Notice the connector to power is at the top left and the output is at the bottom right. The amplifiers follow the "high voltage up-low voltage down" rule and everything is separated by function.
You will want to use an appropriate grid size to align your wires (about 50 mils - 1 mil is 1 thousandth of an inch, NOT one millimeter) and use labels to make the values and functions of each part clear.
Most ICs are drawn as rectangles. A resistor can be shown as a long rectangle or a zig-zag shape. Capacitors are using two parallel lines of some length, while a battery is a long line in parallel with a short one. Some shapes are made for special functions (a triangle is usually an amplifier). Here are some examples:
Sometimes you will need to make a new schematic symbol if your software doesn't provide it. Be sure to group pins on your new symbol by function, not the location on the physical package. Power should be on top, ground on bottom, and inputs on left and outputs on right.
Once you have your symbols in your schematic, you might notice they will have associated letters and numbers. For example, U1 or R4. These are called reference designators, as shown above in the example BOM. The letter tells you what kind of component it is. "U" means some IC while "J" is a connector and "R" is a resistor. The number is just clarifies which of that type it is. Naming 15 different resistors "R" isn't helpful, so they are labeled R1 to R15. These are usually automatic, but you will have to hand-label their values, of course.
When your schematic is complete, you will want to run ERC, or electrical rules checker, through your software. In Diptrace, this is done by clicking "Verification" at the top menu bar and then selecting "Electrical Rules Check" from the drop-down menu. In KiCad, it is Inspect>Electrical Rules Check. This will ensure that your wires are connected appropriately and that you didn't make any egregious errors.
What is a layout? It is like a map for how your physical board will be arranged. PCB's are built layer by layer with copper layers for connectivity and insulating layers to provide mechanical rigidity and form. The boards are covered with something called soldermask, so that when you start soldering, the solder will stay only within the exposed pads you designate. These pads are made of copper and connect to the copper layers in the board. Here is an example of both through-hole and surface mount pads with the lines of connectivity in light green (the other smaller holes you see are called vias, which you'll learn about later):
Layout begins by assigning footprints to each of the components in your schematic. Footprints are the physical representation of the schematic symbol of a component. For example, a capacitor footprint will usually be two parallel rectangles, as shown below:
There is a function in your software that allows you to import your schematic so that the footprints connect like they're supposed to. This is called LVS (layout vs schematic) and is often included in DRC (design rule check).These connections are those light green lines you see above. You can even use the autorouter to do this, but it's not a very intelligent function. It's better to do it by hand. Make sure that when you are connecting pads to one another that none of your lines cross! Your layout needs to be planar. You may find that this proves difficult, if not impossible, so to get around this, use vias. Vias, which are holes that go between the back and front of the board, need to be proportional to the width of the trace (the term for the light green lines). See the following figure. Below is a calculator for finding the appropriate width of a trace, which need to be larger to carry large currents.
When routing, use net classes (e.g. power, ground, etc), and try to keep traces short, especially for high currents, since traces have resistance. Fill zones, or copper pours (see example below), help to dissipate heat across the board and connect large areas together. Follow datasheet recommendations for help.
Once you've arranged them in a way that makes sense for your project (i.e. connectors should almost always be at the edge, with the SMT IC's near the center), consider the Design Rules. These are the minimal manufacturability requirements of the board. For example, drill sizes have to be a certain diameter, along with trace widths. The smaller everything is, the more difficult and expensive it will be manufacture, if not impossible. At the end of your design, you will run DRC, which is similar to ERC, but instead checks that you have followed all the rules of manufacturability. Here is an example of a layout:
General steps to follow:
Begin by drawing edge cuts. This is the yellow rectangle that surrounds the components. It determines the outermost edge of your board. Usually, the size of your board is dictated by mechanical requirements, so this is almost always the first thing you should do.
The other two colors of rectangle define the ground and power planes that you will be connecting your components to.
Check ICs' datasheets for a recommended layout. How much space does the recommended layout require? In the above example, U1 had a recommended layout that suggested the capacitors and diodes around it be arranged as so, with copper pours connecting them where appropriate.
Next, place the connectors at the edge of your board. In this example, it would be the USB connector (it wouldn't make much sense to put that in the middle). Place power-related components and their external components after that, according to the datasheet's recommendations. Include any fills or thermal vias that it recommends.
Place the rest of your components (usually passives and indicators) and then add any additional filled zones you may need.
Lastly, route all nets not connected to a fill zone and adjust the size of your fills as necessary after creating them. Add routes and vias to connect your fills.
Other things to consider include the following:
Traces have resistance (they will heat up, decreasing efficiency and wasting power), have inductance (current through them can't change instantaneously), and have capacitance (causes signals on one wire to show up on others). Increasing trace width reduces resistance and inductance. Decreasing trace length does the same.
Vias have inductance and add length, so put them in parallel when you must use them.
Decouple correctly by placing capacitors close to the component you are decoupling and size the capacitor correctly so that inductance doesn't dominate. See datasheets for recommendations.
If you are creating a complex with a lot of components, consider using the "Manhattan Routing" strategy. It has only one simple rule: all horizontal traces go on one layer and all vertical traces go on another layer, and traces go to the other layer (with a via) whenever they need to turn. If your board is very simple then this probably isn't worth the effort, but for large or dense boards this strategy can make your life much easier.
Make sure you have done all of the following before a review, and before boards are submitted for manufacturing.
All passives should have values visible.
Important nets should be labeled
E.g.: V_in, 3.3V, GND, DEBUG_RX, DEBUG_TX, ACCEL_SDA.
Text should not overlap.
Components that are not easily replaceable should have Manufacturer and Datasheet filled out in Component Properties.
"Not easily replaceable": ICs, connectors, fuses, any unusual components such as a massive electrolytic capacitor.
Schematic should be broken up into modules (surrounded with a box) to aid readability. Label each module with text.
E.g.: radio, voltage regulator, reset line, programmer port.
Use netports to prevent lines going everywhere.
Test points should be added to ALL nets that we MAY want to measure at some point.
Double check all patterns
Add silkscreen
Pins on ports such as UART, programming ports, actuators, etc should be labeled
Move reference designators (RefDes) if necessary
Tip: F10 allows moving reference designators, 'r' for rotate
Place board name and version (eg Ground Station v3)
Calstar Logo (use reflected version if placing logo on the back of a board)
File > Renew Layout from Schematic
Verification > Check Net Connectivity
Verification > Compare to Schematic
Verification > Check Design Rules (F9)
Use to calculate impedance of traces, primarily for matching against 50 Ohms
Note: we have our boards manufactured to be 31 mils (this is the substrate height)
The substrate in our case is FR4
Use to determine minimum required trace widths based on current range
Bay Area Circuits:
Stay within BAC's standard capabilities
InstantDFM is a simple tool from bay area circuits that you can use at the very end of the board design process to verify that your board meets their manufacturing requirements (like minimum trace widths, via sizes, copper to edge clearance, etc). Before you submit any board for manufacturing, you should always run it through instantDFM to verify that there are no errors.
To jump right in, go to and then .
If you've made your own schematic symbol for a component, you will likely have to make a footprint for it as well. Footprints are described . The following link will show you how to make new component footprints.
Different from the component package, this is how the components are actually shipped. Make sure you can order the amount you want; some components are sold in units of 5,000! Generally, Tube, Tray, and Cut Tape and fine, whereas Tape and Reel and Digi-Reel have minimums in the thousands. See the for more details.
does an excellent job at summarizing when you should use a BJT versus when you should use a MOSFET.
A switching regulator, on the other hand, is relatively efficient with power and is generally more precise. These converters are important to supply the correct voltage to a component in order for it to work properly. A switching regulator that steps up voltage (at the expense of current) is known as a boost converter, while one that steps down is known as a buck converter. There are also .
When you have finished your layout, go through this to ensure that your board is ready for fabrication.
Use the HOPE PCB Decal checklist:
Use BAC's InstantDFM to verify they can produce your board within standard capabilities:
Impedance calculator:
Trace width calculator:
Manufacturing capabilities:
Stackup capabilities:
Tutorials specific to the Avionics subteam
How to debug hardware and firmware problems
Start with these steps to avoid common mistakes:
Make sure the PCB is powered (either by power supply or by battery). Indicator LEDs are generally helpful for this (if they were placed correctly).
Check for correct DC voltages with a multimeter at all input pins.
Check for continuity on nets. You can also inspect solder joints.
Check regulator outputs with a DC multimeter AND an oscilloscope.
Check input voltage at all ICs with both DC multimeter AND an oscilloscope.
Check for amplitude and frequency of all external oscillators with an oscilloscope.
Check bus signals with an oscilloscope.
After you determine that the PCB is powered correctly and connections are intact, see the firmware debugging to determine more complex problems.
Prior to checking firmware, make sure the hardware is functioning as expected using the hardware debugging steps.
Then,
Sanity check you can control GPIO pins by flashing a simple program that sets GPIO pins high, and another program that sets GPIO pins low. Check output using a multimeter.
Check the fuse bits are what you expect them to be.
Check the microcontroller is running at the rate you expect it to using UART. This may be a fuse bit issue as well.
Once you have confirmed basic control of the board and microcontroller, test your firmware by adding status LEDs to show general state of code (particularly useful to check control flow in a state machine). Add additional output at critical points in the code. Forms of output include GPIO pins, radio, UART, and LEDs. This should allow you to see where your program is going wrong.
Modularize the code as much as possible and test modules from simplest to most complex. Reduce complexity in the code.
This is a slightly more professional way to solder boards. Faster, but with some risk
Reflow Oven: essentially a toaster over that can follow a pre-programmed temperature profile
Solder paste: similar to solder, but comes in a syringe and is paste-like. When heated past a certain temperature, solder paste flows, and upon cooling forms an ordinary solder joint.
The Chenming Hu Innovation Lab (Supernode) contains a reflow oven. STAR as a team has used it successfully to solder components. Here is how to do so:
PCB to be soldered henceforth referred to as the "target PCB"
PCB blanks, preferably large and of the same height as the target PCB
Stencil (usually ordered from OSH Park)
Solder paste (63/37 Sn-Pb)
We currently have a syringe labeled CalSTAR in the Supernode refrigerator
This is expensive, so try not to waste it
Masking or other tapes
Scraper / credit-card-sized card
Clean the target PCB with isopropyl alcohol (isopropanol)
Arrange spare PCB blanks in a configuration around the target PCB as follows:
Make sure the PCB to solder is snug and there are no gaps around it. If the blanks are thinner (e.g. 31 mils) than the PCB to solder (e.g. 61 mils) or vice versa, you can double-stack. It is important to have the blanks be at the same height as the target PCB
Next, position the stencil such that the holes in the stencil line up perfectly with their respective pads
Once alignment has been achieved--and be sure that it's as close to perfect as possible--tape one edge only of the stencil to the blanks and orient it so the taped side is away from you:
Squeeze solder paste from the syringe "above" (tape side) each section of pads
You will likely have to add more solder paste after the first pass. It is OK to recover solder paste, move it around, etc., but be very careful not to scrape too much side-to-side or away from you. The stencil must remain flat and in position
Continue spreading the solder paste around until each pad clearly has solder paste on it. We have found a steep angle allows for the collection of paste from the top of the stencil, while a low angle and higher amounts of downward force can help to get paste through the holes in the stencil
Gently lift the stencil from the board and flip it "up", exposing the board
Using tweezers, carefully place all components according to the reference designators/layout.
After placement, verify each component is securely on the board by gently pressing down on the top of the package with tweezers
Remove the board gently from the blanks, without tilting it overly
After placement, components should be somewhat attached to the board--the solder paste is sticky. All components should be aligned with their footprints.
It's finally time!
Before starting this section, open all windows in the vicinity of the oven. This process may produce unpleasant and carcinogenic odors.
Open the reflow oven and carefully set the board on the ceramic / kapton tape spacers. Do not place the board directly on the metal tray of the oven
Close the oven door
Turn the oven on with the switch on the back. You will have to walk around to the other side of the oven to access it
Select the pre-set reflow profile for 63/37 solder.
Start the heating sequence.
Even though the reflow oven will not quite be able to follow the profile specified, we have had no known problems with just letting it run--the temperatures reached are sufficient. Abort only if it is abundantly clear that the oven will not reach anywhere near the desired curve, and restart--if the oven starts from 50C, there should be no significant issues.
Allow the oven to cool, and carefully remove your newly-reflowed board after waiting a few minutes for it to cool down!
Inspect the board for any "tombstoning", shifted parts, failed connections, etc. Some amount of these are normal and can be reworked with the hot air rework station or soldering iron.
Inspect smaller connections under the microscope, and retouch if necessary with a soldering iron
Do not be alarmed if the board is slightly browned--it's been toasted, after all
Learn git and avionics' git workflow
You'll find all of Avionics' sources on our Github, including schematics, layouts, firmware, and software. This Github org also contains repositories of other STAR subteams.
Windows 10 supports running a proper Linux development environment using Windows Subsystem for Linux. Installing and using this is highly recommended on Windows.
Make sure you have a Github account and you have joined the Github STAR org Avionics team by messaging the avionics lead (currently Cedric Murphy @Andalite1999#4769). For git installation, see here.
There are many great git guides out there!
Learning git takes time and can be intimidating! If you are worried you're about to mess-up your repo, or have already messed up your repo, ping someone in Discord!
Short list:
Clone the repo.
Create a new change branch from the master branch.
Make changes.
Rebase onto master branch.
Submit a pull-request on Github.
When approved, merge into master!
Clone the "repo" onto your local computer in by running the following command in terminal:
This will copy the repo and all its current files into your directory. Make sure to read through the relevant documentation in the repo before making any changes.
The --recurse
(short for --recurse-submodules
) tag tell the computer to execute
after cloning. For libraries that are used in multiple repositories, such as hardware-sch-blocks,
it is cleaner to create a separate repository for the library and embed it as a submodule instead. Because submodules are not normally downloaded with git clone, --recurse
is necessitated. For a thorough guide, see tutorial.
A branch is a separate copy of a git repo that can have its own changes separate from other branches. A branch can later be incorporated back into the "master" (main) branch. We use branches to develop and test changes before we merge them into master, which we expect to remain stable and flight-ready.
Create and checkout a new branch:
Switch to an existing branch:
Edit or create files with your desired text editor, which should be vim.
Register changes with git using git add
. For example if a.txt
is a new file and b.txt
is a modified file, do:
Then, "commit" changes into git. This saves changes into a snapshot which you can look back at.
Often you will work with other members on a change on a given branch, so the new changes (the commits) on the branch will need to be pushed to Github. Do this by running:
The first time you do this from a new branch, git will tell you that no remote exists. Follow the instructions it outputs to create the branch on the Github side.
Often, there will be many commits on a branch. To keep git history on the main branch concise and informative, we often squash the commits on a branch into a single commit that describes the whole change. There are two primary ways of doing this:
or
While squashing changes gives a single commit that describes the entire change of a branch, rebasing onto master ensures linear commit history of the master branch in case there have been changes on master since your change branch was created. Rebasing does this by essentially taking the current master branch and replaying all your changes on the change branch onto the new master. Rebase onto master, once commits are squashed, by doing the the following from the changes branch.
You may encounter rebase errors here depending on what changes ocurred on master. Git will let you know which files you will have to merge manually and how to continue when done fixing.
Make sure to test all functionality again after rebasing onto master!
Finally, the change is implemented and tested. A pull-request is where the final review of the change is done before it is merged into master.
To submit a pull-request, do a final git push
and then go to the Github website. Select the branch and using the Github UI select submit pull-request. Add relevent reviewers and ping them on Discord.
As reviewers comment, you will likely need to make changes. Once all changes are made and reviewers approve the change, hit merge!
Some commands you will find useful.
Show commit history:
Optional: Download http://leo.adberg.com/gitconfig and save as ~/.gitconfig (replacing user info) To see a view of all commits and branches:
To see the status of your local repo, you can run:
These slides have nice descriptive diagrams! Check it out!
Reviewing is one of the most important parts of bringing up a board – we don’t want to waste money or time on a flawed design. Consequently, it can take practice to really know what to look for while reviewing a board; there’s no substitute for watching an experienced engineer at work. However, most boards we make have quite a bit in common, so a lot of failure modes are also shared. For anything simple, the below guide should be a good starting point; for anything analog/RF, high-speed, or high voltage/power, additional care should be taken.
In general, when reviewing a board, make notes and open issues on whatever issue tracking system you’re using (GitHub, Jira, etc.). Let the responsible engineer (RE) review those issues and make changes – don’t make changes on your own. Especially with schematics, merging changes from multiple people can get messy.
Reviews take time to be done thoroughly, so (especially if a single person is doing the review), alot time in terms of days, not hours. Additionally, do not think of a review as a 'final check' before a board is put out for fabrication. It may take weeks to make changes and update until a board passes review.
Make sure you include the schematic file (and layout if applicable) as well as a bill of materials (BOM) that includes DigiKey part number (or Mouser #, or direct link if applicable), name, quantity, and price for literally everything on the board.
At the level of the board, one of the first steps is to ensure that all interfaces to other systems are met. This usually means that there should be power, a programming port (per MCU), and some combination of actuators + sensors + communication. Familiarize yourself with the function of the board within the system. The project page for the board or the system it is part of should contain the description of these functions against which you can compare the schematic.
Component level review should be exhaustive. This means pulling up a datasheet for every single component other than simple passives, and comparing side-by-side with the schematic. Things to look for:
Reference designs (in the datasheet) are followed
Directionality of I/O lines
Acceptable voltage ranges
Power lines
Every Vdd/GND pair should have a decoupling capacitor whose value matches what’s suggested in the datasheet
Analog power should be separated from digital power (sometimes with additional filtering on the analog lines).
Certain types of I/O (I2C buses, for example) require pull-up or pull-down resistors. If you’re not sure where these are required, ask.
Sometimes, components will have requirements on where they should be placed during layout (for example, decoupling caps should always be placed near the IC being decoupled). Make sure these are annotated on the schematic.
Lastly, at the system level, you should ensure that your power block can supply enough current/power to meet the peak needs of everything on the board, with overhead. Also ensure that top-level interfaces to other parts of the system are satisfied.
TBD
Setting up ground station software to run on laptop
First, install npm
. Then, run $ npm install
. This will take a while as there are many dependencies for the ground station software.
If your terminal fails on
try uninstalling and reinstalling node.js.
If you are getting a git error such as
try running npm cache clear
.
If you are on Windows and are installing npm
in WSL, npm
will likely fail if you have npm
also installed in Windows itself. Install npm
in only one of the two.
To run the program, you will first have to plug in the ground station and then determine which device the ground station is.
On Windows, open Device Manager
, look under COM Ports
. Remember which are listed, and then unplug ground station. The Device Manager will refresh and, if the ground station was correctly detected by Windows, one of them will have disappeared. You can plug ground station back in for it to reappear. It should have a name in the format COMx
where x
is a number. If you installed npm in Windows, you will run the ground station software with the command npm start COMx
. If you install npm in WSL, you will run the ground station software with the command npm start /dev/ttySx
where x
is the same number as in Device Manager.
Make sure you have logs
folder in that directory or else this will fail!
Open up a web browser and go to . If opening this gives you a blank page, inspect element
. If the error says something along the lines of cannot find dist/openmct
then...we really don't know. For now, contact someone who has it working to email you their openmct
package. Then from ground_station_openmct/node_modules
run rm -rf openmct
then unzip the emailed openmct package into ground_station_openmct/node_modules
.
About ham radio and how to get your license
Professor Miki Lustig often teaches a Ham Radio decal, along with his class EE123: Digital Signal Processing. You can check for information.
Ever think about building your own radio? To talk to your friends across the county, the country, or around the globe? How about some astronauts on the ISS? Do you like the idea of bouncing radio waves off meteors or even the moon? Think you have what it takes to learn CW ("Morse code")? Amateur radio operators ("hams") do all this and more. By getting licensed with the FCC, you can join the ranks of 8 million radio amateurs in the U.S. Getting licensed allows you to:
Build and operate your own radio equipment
Transmit on radio frequencies (not channels) exclusive to radio amateurs
Transmit up to 1500W*
Experiment with new communication schemes
If you are enrolled in the decal, all of the following information should be provided to you in class or on piazza. There are three levels: technician, general, and extra. The steps for registering for a technician ham radio exam are as follows:
Register on the FCC website to get an FRN (FCC Registration Number). You will need this for all future ham exams. Click , then click "Register and receive your FRN."
After selecting "individual" and "yes" to the first two questions, fill out all your information and submit.
While you wait to get your FRN, you can search for exams in your area by clicking . Note that there will probably be one in Berkeley at least once a semester. is what you should bring.
There are many resources on the ARRL website to study for the exam, such as the . However, seems to be the best place to do (many) practice exams.
Note that you will get your call sign after you have passed your exam.
Use a scraper or card to press firmly down on the stencil and spread solder paste, drawing the scraper toward you. At no point should you scrape away from yourself, lifting the stencil!
Alternatives to LiPo (Lithium Polymer) batteries that are suitable for high temperatures.
The maximum recommended/tested temperature for LiPo batteries is 60C [1].
When LiPo batteries operate at high temperatures, they are at risk of severe performance degradation, and produce gasses such as O2, CO2 and CO. This is because of the interactions at the electrolyte-electrode interface [1].
This has caused significant distress to our team, as we compete in New Mexico which routinely experiences extremely high temperatures.
Batteries better suited to high temperatures will have different internal chemistries that have high thermal stability. This is not a new problem and more suitable batteries do exist. A few have been listed here. More information will be added if we find reliable suppliers for these batteries and can try to work with them ourselves.
References
Battery Type
Max Temperature
Potential Suppliers
Lithium Iron Phosphate (LiFePO)
200C [1], [2]
batteriesinaflash.com
Lithium Thionyl Chloride (LiSoCl2)
95C - 125C [3], [4]
Tadiran Eagle Picher
Jauch
Amazon?
How to solder/populate a PCB
Please note that there should be a through-hole and surface mount soldering workshop roughly every semester; ask on Discord for a date and time. It is highly recommended that you attend this workshop, as this page is more of a supplement than a stand-alone tutorial.
Now that you have a PCB, you are ready to solder. Make sure you have the following supplies:
Soldering iron
Solder
The board that needs soldering
Components to solder onto the board
Flux (either liquid in syringe or pen form)
Tweezers (for surface mount soldering)
Solder wick (not necessary, but useful)
Solder sucker (not necessary, but useful)
When putting together your board, remember to test as you solder. This will make sure that you have a better idea of where a bug is if you run into one. This means soldering on a module and then testing that module before moving on to soldering another module. Refer to "Using Lab Equipment" on information relevant to testing. An example of how to break up soldering a board into modules is as follows:
Voltage regulator/power input. Test with a multimeter (and by power LED).
Microcontroller. Test by writing a simple program to verify that you can use digital input/output pins. Can also verify by flashing a program that uses the debug UART port.
Sensors/actuators (one component at a time). Verify the component works by interfacing with the microcontroller. This may require having some code ready to communicate over I2C or SPI!
Remember to put away all tools you used when you are done. Keep whichever space you are working in clean.
Through-hole soldering steps (repeat these steps for each joint):
Place your circuit element into the PCB.
Melt a small blob of solder on the tip of the soldering iron. This is called “tinning the tip” and it improves the transfer of heat from your soldering iron to the component you want to solder. Make sure to do this to avoid oxidation and permanently ruining the tip.
If necessary, apply flux to the metal ring on your PCB. Flux is usually more important for surface mount soldering.
Touch the tip of your soldering iron to the metal ring and component leg (of a through-hole component) at the same time. (See diagram below)
Feed solder into the joint (not the soldering iron) while this is happening. It should only take a couple of seconds at most to fill the joint with a proper amount of solder.
After enough melted solder is present, stop feeding solder and remove the tip from the joint.
Clean the tip of the soldering iron by dabbing the tip on a wet sponge.
Let the joint cool down for at least 5 seconds and then trim the ends of the wire(s).
The following tutorial is for through-hole soldering:
Surface mount soldering is a bit more difficult. The components are small, and it's easy to short pads (the metal parts that you're soldering onto) and components together. But all it takes is practice!
The steps to do surface mount soldering is similar to through-hole:
Place your circuit element onto the PCB.
Tin the tip. Very important.
This is when it's good practice to use flux! Apply some to the pad before soldering. After you're done, put some flux on the solder blob and apply heat with the soldering iron to flatten peaks.
While soldering, touch the tip of your soldering iron to the metal pad and edge of the component leg at the same time.
Feed solder onto the pad (not the soldering iron) while this is happening. It should only take a couple of seconds at most to cover the component and pad with the right amount of solder.
After enough melted solder is present, stop feeding solder and remove the tip from the pad.
Clean the tip of the soldering iron by dabbing the tip on a wet sponge or brass sponge.
Let the joint cool down for at least 5 seconds and then refer to the flux step above.
The following tutorial is for surface mount soldering:
There are many free through-hole components around Supernode, and you can just ask someone for surface mount components. It's important that you practice. Please ask for help if necessary.
How to use the lab equipment
The power source is used in place of a battery when running hardware tests. You can connect this to your circuit by using banana plugs, pictured below. By convention, red should be connected to the (+) terminals, and black to the (-), or ground, terminals.
As described by the gif above, follow these steps to set up the power supply:
Turn on the power supply by pressing the Power on/off button.
Set a current limit. To set a current limit, first push the "Display Limit" button. Next, push the "Voltage/Current" button on the right of the machine so that the current is selected (blinking). Then, use the arrow buttons on the right to select the digit you want to adjust, and then use the knob to adjust the value of that digit. Generally, we will use 0.100A unless otherwise noted. While 0.100A may seem small, it is still enough current to cause serious damage to the PCB you're testing.
Select an output: This device is capable of outputting 3 different voltages with maximum values of 6V, 25V, and −25V respectively. Make sure to push the button for the output you would like to use.
Set the voltage: After selecting the correct output (step 3), set the voltage to the desired value. To do this, push the "Voltage/Current" button so that the voltage (displayed on the left) is selected (blinking). Then adjust the value using the arrow buttons and knob, like when you set the current limit. Make sure you are adjusting voltage and NOT current.
Turn the output on: By default, the output of the device is turned off. For the device to actually output current, press the "Output On/Off" button. Always turn the output OFF whenever you are idle / don't need the Power Supply!
Note that these probes have the same connector as the oscilloscope probes. But beware! The function generator and oscilloscope probes have different impedances, which means if you use the wrong probe for the instrument you're using, your output will give you absurd voltage values.
Multimeters can come handheld or in the lab as shown above. They are used to measure the resistance, current, or voltage difference across two terminals. They can also be used to test for continuity. This means that you can determine what points are shorted together or not. You can use banana plugs with this machine, but the probes shown below are generally better to touch at specific points.
Follow these steps to set up:
Turn the multimeter on.
Connect the probe to the multimeter. You can determine what terminals to plug the probes into by looking at their labels.
To measure voltage or resistance or to test for continuity, plug the red probe into the terminal with the V, Ω, and diode symbol.
To measure current, plug the red probe into the terminal with the capital "i" next to it.
The black probe should be in the terminal labeled "LO" between them.
Touch the ends of each probe to the nodes on the board that you want to measure across/test continuity for. You can toggle the information you want to see on the multimeter by pressing the DC V (for DC voltage), AC V (for AC voltage), Ω (for resistance), or cont ))) (for continuity) buttons. When you press cont, it will say open until it is shorted. If there is continuity, it will beep.
The oscilloscope can be used to measure signals that change over time. Unlike a voltmeter, which only shows the instantaneous voltage value, the oscilloscope shows a graph of voltage versus time, which is useful to see how devices respond to inputs. This piece of equipment may look pretty complicated, but most of the knobs are to adjust axes. Oscilloscopes can also be used to simply measure DC voltages, as one would with a voltmeter.
The oscilloscope probe that connects to the color-coded metal terminals at the bottom looks like this:
Follow these steps to set up:
Turn the oscilloscope on (button at the bottom left corner).
Connect the probe to one of the 4 input channels (yellow, green, blue, or red). Make sure that the channel is on (indicated by a green light on the channel number). To turn a channel on (when it was originally off), simply press the corresponding numbered button. To turn it off, push the button again, and the light will be off.
Connect your probe to your circuit.
Auto Scale: Potentially skip steps 5-7 by using the "Auto Scale" button (see the image above) to automatically scale the axes. Don't get too dependent on the "Auto Scale" button; sometimes it doesn't do a "good enough" job.
Adjust the horizontal axis of the plot. The large knob at the top (immediately to the right of the screen) controls the horizontal time axis and allows you to zoom in or out. The time increments represented by the tick marks on the plot are indicated at the top of the screen.
Adjust the vertical scale. The larger of the two knobs for each channel (the one above the button with the channel number) allows the vertical scale of the voltage graph to be adjusted. As with the horizontal scale, the number of volts per tick mark on the graph is marked at the top of the screen.
Adjust the offset. In some cases, signals will appear off-screen; adjusting the smaller of the two knobs (below the channel number button) corresponding to each input will shift signals up or down on the plot.
Add measurements such as average voltage, amplitude, etc. Measurements can be added by pushing the "Meas" button and using the buttons below the screen to select and add measurements.
The function generator can be used to provide test inputs to your circuits. It acts like a power source, but there is a difference. While the power supply is capable of giving you a fixed voltage, the function generator can output sine waves, square waves, and a variety of other waveforms that change over time. Sometimes the function generator is useful if more independent DC supply voltages are needed than the power supply can provide.
Steps to set up the function generator:
Connect the function generator probe (pictured above) to either channel 1 or 2.
Press the "1" button for channel one and the "2" button for channel two to see their menus. Here, you can set the output load (for example, high Z), voltage limits, as well as turning the output on and off (as you would with a power source).
Press the button labeled "waveforms" to get a list of waveforms. Press the blue buttons on the bottom to select your desired waveform.
Press the "parameters" buttons to set the parameters of your waveform. Here you can use the keypad, knob, and arrows to adjust the frequency, amplitude, offset, duty cycle, and phase of your waveform. Again, use the blue buttons at the bottoms to toggle between parameters. You can also press "units" to change the units.
How to code in C, given that you already have knowledge of other programming languages.
A useful reference linked here.
Primitive Data Types:
int
: integer
float
: floating-point number, used to store decimals.
double
: double-precision floating-point
char
: ASCII character
In the <stdint.h>
header, additional types are included for defining integers by size (in bits) and sign. A useful one is uint8_t
(an unsigned 8-bit integer type) to represent a byte.
Computers prefer to interpret things in binary, so the use of bit operators is often useful in C to more accurately visualize what happens underneath the abstraction. The most common operators are:
These don't seem super useful on the surface, but they will be once we start dealing with registers.
The microcontroller datasheet is your best friend!
I/O devices in a microcontroller (such as sensors or actuators) are mapped to memory addresses - that is, you can get a sensor value by reading from a location in memory, or modify an actuator output by writing to another location. What does this mean for you? Embedded C handles this through the use of registers. A register is a storage element in the processor, often used to hold intermediate values during computations. However, certain specialized registers are used to perform hardware functions, and we can access these registers by using their names.
For an example, let's look at the I2C interface on the Atmel ATMega328, a common microcontroller that is famously used on Arduinos. I2C designates a master and a slave device, and the master can individually address a slave device by sending its address on the common bus line before sending or receiving data. There is also a common clock line. Taking a look at page 292 of the datasheet, we find descriptions for each register used in I2C operation.
This register holds an 8-bit value that can be read from or written to (as we see from R/W in the access line), that determines the speed of the SCL line, which is the common I2C clock. The conversion of this value is as follows: SCL frequency = CPU clock frequency / (16 + (2 * TWBR * Prescaler)), where the prescaler is set in a different register.
Let's say I want an SCL frequency of 100 kHz from a CPU clock frequency of 16 MHz. I can achieve this with a prescaler of 1 and a TWBR of 72: 16 / (16 + 2 * 72 * 1) = 16 / 160 = 0.1 MHz. I can assign this TWBR rate simply like this:
So far, so good. Let's move on.
Whoa, okay. This one's a little trickier - we have two different values here. What should we do?
Let's go back to our bit operators from earlier. If I want to get only the TWI Status Bits (that is, TWSR[7:3]), I can simply right-shift the TWSR value to eliminate the three lowest-order bits.
What if I want to write to the prescaler bits without overriding a bit I shouldn't be writing? Technically, I can't override a read-only bit even if I try, but this will illustrate my point just fine. A useful feature of the OR operator is that if I OR something with a 0, I just get that same value - that is, A OR 0 = A. But A OR 1 = 1 no matter what A is.
Now consider this code:
What does this do? I'm ORing the TWSR value with a binary value that essentially passes the top six bits unchanged - since I'm ORing with zeroes. However, I'm forcing the bottom two bits to be 1s, because as I pointed out, 1 OR anything is 1. So this code forces the prescaler to 64, per the table above, but leaves the other bits unchanged! I can simplify this a bit:
This is great, but what if those prescaler bits are already 1s and I'd like to set them back to 0s? ORing won't help, because they'll be 1s after the OR as well. This is where the AND operator comes in handy. Note that for any A, A AND 0 = 0, but A AND 1 = A.
Now consider this code:
This is a similar trick. ANDing the top six bits with ones passes them unchanged, but ANDing the prescaler bits with zeroes forces them to zero. So the top six bits don't change, but the prescaler is now 1. Let's simplify this again:
Let's say now I want to make the prescaler 16, so I want to flip the single bit TWSR[1] to 1. Rather than typing out the binary mask I want to use, we can shortcut:
This left shift operator evaluates to 0b00000010, which is exactly the mask I wanted to use. Similarly, I can flip it back to zero with this:
This produces the mask 0b11111101.
Often, each bit in a register can signify different settings for the microcontroller, and is given a name.
In the I2C control register (TWCR), each bit (excluding bit 1) defines a setting of I2C. The datasheet defines the purpose of each bit. Below is the definition of bit 2, TWEN.
TWEN defines whether I2C is enabled or not. I can set this bit using the bit shifting, ANDing, ORing, and NOTing operations.
Using the predefined names makes the code easier to read and understand, and thus more maintainable, over using raw hex values.
And there you have it! You can use combinations of these tricks to do a lot of powerful things.
For a more complete reference on the C language, see the text below:
http://www.dipmat.univpm.it/~demeio/public/the_c_programming_language_2.pdf
A walkthrough of our component selection process for designing boards.
One of the challenges of circuit design is narrowing down exactly which components you want to use. For example, suppose you need to include a zener diode as part of your circut. A quick internet search on supplier websites reveals more than 70,000 possible options! How are you supposed to narrow it down?
This option is relatively simple but works very well: browse through some of our old electronics projects and re-use components that we've used before. For example, if you need a zener diode, check our past projects to see if any of them incorporated a zener diode, and re-use that specific diode for your current project (as long as that diode meets your current project requirements). Some of the projects that you can browse are:
Open up kicad and browse through their schematic symbol libraries. In these "Kicad default libraries" you can find a whole host of specific part numbers for each general type of component (amplifiers, transistors, etc). There are two main advantages to using components from the Kicad default libraries: first, obviously, you'll have easy access to the symbol and footprint for your part, without having to make them yourself or search online. Second, by virtue of the component being included in Kicad's deafult libraries, you'll know that it's a very popular component.
If we go back to our old example of trying to find a zener diode, here's how we can search the Kicad default libraries. First, open up the schematic editor and select the button to add a component:
Then, type "zener diode" in the search bar:
Most of the options it shows us here at the top are 'generic symbols' and aren't specific part numbers.
If we scroll down, now we can see some specific part numbers. For example, here I've selected the BZV55B2V4 zener diode, and if we later decide we want to use it in our project, we can buy that specific diode from digikey.
Sometimes, if a component isn't available in the Kicad default libraries, you can find it in an online Kicad library, which you can download and incorporate into your project just like a component from a default library. One of the best resources for finding these online kicad libraries is snapeda.com. This website allows your to search by part type (or by specific part number) to get symbols and footprints that you can integrate into your kicad project.
If you go to the main page and type "zener diode" then the search results will look something like this:
You can click on each individual part to see more details about its symbol and footprint. Note that not all components will have both a symbol and footprint provided--some have only a symbol, some have only a footprint, and some have neither. Components with the will have a symbol, and components with the will have a footprint. If you get a component with only a symbol, it is possible to make the footprint yourself and incorporate both into your project (and vice versa). However, note that symbols are generally much easier to make yourself than footprints.
One of the great things about SnapEDA is that it tells you how popular each part is by displaying the number of times that each symbol and footprint has been downloaded. If something has over 100 downloads, that usually means its a very solid choice. For this reason, looking up parts on SnapEDA is still useful even if you already have the symbols and footprints. If you're trying to choose between two zener diodes, and one of them has much more downloads on SnapEDA than the other, then that might help to inform your choice between them.
Digikey.com is the main website that we use to search for and purchase parts. However, we frequently buy parts from other sources as well--mouser.com is a good example, offering almost all of the same features as digikey. We also buy parts from Amazon sometimes, like the ESP32s used in the LE2 ground system.
For now, though, you can stick to digikey, as that will make things simpler. Continuing with our zener diode example, you can start by typing 'zener diode' into the search bar at the top of the screen. Doing so will lead you to a page that looks like this, where you can select the category of components to browse:
Click on "Diodes - Zener - Single." Next, you'll see a page that looks like this, where you can browse all the specific components to purchase:
You can start narrowing things down by selecting some filters. Under "product status", select "active"--this is one filter that you can always select right off the bat. After that, scroll through the rest of the filters and select the ones that apply to your project. For example, maybe you know that you'll need a zener voltage of 12V exactly--in that case, you can go to the "Voltage - Zener (Nom)" filter and select 12. Additionally, maybe the project requirements stipulate that the zener diode needs to support 500 mW of power; in that case, you can go to the "Power - Max" filter and select every power level above 500 mW. Oftentimes, you can also go to the "Mounting Type" filter and select "surface mount" because we usually use surface-mount components on PCBs due to their small size. (Though sometimes we do need to use through-hole components, usually when the components have some kind of high-voltage or high-current function).
Press the red "apply all" button after selecting your filters. This drops the number of results down to about 617. Next, unless you have a specific part number in mind, go to the "Quantity Available" tab and press the down arrow button to sort in descenging order or quantity available. This is done for two reasons; first, the parts with a very high number available are generally the most popular, and therefore the best to use. Second, we have had some problems in the past with parts that are out of stock on digikey (for example: we designed CAS in 2020 and included a component called the BNO055. That component ended up going out of stock, and as of 2023, it's still out of stock. Depending on how far in the future you're reading this, it may still be out of stock today!).
From here, you can scroll down the list of most popular components and note down any that look appealing. Note that, when digikey reports the quantity of a component, they include both the quantity that they have "in stock" (the normal way to buy them) as well as the quantity available on the "marketplace." The marketplace is relatively new so STAR doesn't have much experience buying from there. If you find a component you really like that's only available on the marketplace, by all means go ahead and buy it, but if you want to stay on the safe side, then stick to the components that are listed as "in stock" on digikey. At this point, you'll probably be able to get a shortlist of several components (10 or so) and start deciding between them.
Look at options from a reliable vendor. Some vendors that make lots of good components include Texas Instruments, Onsemi, Diodes Incorporated, Analog Devices, and NXP. Note that digikey allows you to filter by vendor when you are doing the filtering step.
If you are deciding between a few components, read their datasheets. Some datasheets have detailed pinouts, application circuits, debugging information, and more, whereas some other datasheets only have the absolute bare minimum. Components with more comprehensive datasheets are generally a better choice because they'll be easy to use.
Solderability is very important! Components with "little legs" (there's an official package name but I can't remember it) are much preferred because the metal part sticking out makes it relatively easy to solder. In contrast, some components have all their pads directly under the package without any legs at all. This makes it much more difficult to solder, although it can still be done by STAR's capabilities if there are no other options.
Go to adafruit.com if you're interested in getting breakout boards specifically. Adafruit has a much narrower scope than most other component distributors, and they tend to specialize in things that you can connect to an arduino or esp32, such as sensors and actuators. Adafruit usually has very extensive documentation and tutorials for using their components, which makes them a really appealing choice.
Some components are used a lot by STAR simply because our club used them before many times, so they should be prioritized when doing components searches. Some examples of this include the STM32F401RE microcontrollers, which was used in many projects (most notably CAS), as well as the ESP32 devkit-C V4, which was used for ELLIE and LE2 electronics.
If there's one component that is mostly really good but won't work for some reason (maybe its out of stock, or it doesn't meet the required power rating, or something else), try looking for a closely related component. Most manufacturers use a sort of naming convention in which components have more similar part numbers if they are more closely related. Many datasheets will even have an "ordering information" section near the end where they tell you the exact meaning of the naming convention for that family of components.
If the component you're looking for is something that a microcontroller communicates with, you should prioritize components that already have drivers written for them (available online), so you don't have to write drivers yourself.
You can literally just google something like "best zener diode" and see what the top few results are. This isn't the most effective strategy, but sometimes it can work.