xchip lab 0 - VCSFA-MARS/ThinSat-Program GitHub Wiki
To perform this lab you will need:
- IP01 xChip- USB module
- CW01 xChip- WiFi module and processor
- 1 connector piece
Welcome to the xChips Labs! In these labs you will learn the basics of Arduino programming, how to connect and use all the xChips in an xSystem, and a deeper understanding of the underlying science behind everything we've done. Afterwards, we will begin the integration of the xSystem with ThinSats to so that we can accomplish our ultimate mission of conducting science experiments in outer space.
In Lab 0, we will introduce the fundamental xChip configuration and a simple piece of code to demonstrate the interaction between our software and hardware.
Every xSystem will require the IP01, which connects the xSystem to our computer, and the CW01, which contains the microcontroller and WiFi for the whole xSystem.
Take the IP01 and CW01 and click them together using the connectors.
It should look something like this:
Plug it into your USB port, which will power your circuit. The LEDs should flash momentarily while it boots up.
Your IP01 USB module has two switches. Be sure they are set to "B" and "DCE." Some versions of the module will have the switches on the back side of the chip. Having the switches incorrectly configured is a common troubleshooting issue.
In the Arduino IDE, replace everything in the sketch with the following code.
/////////////////////////////
// This lab blinks and changes colors on the CW01 xChip
// IP01, CW01 xChips used
// Written by E. Bujold
/////////////////////////////
#include <xCore.h> // Needed to make CW01 xChip usable
// Define LED locations and variable names
// The LEDs are soldered in place and cannot be changed.
const int RED = 12;
const int GREEN = 13;
const int BLUE = 5;
void setup() {
// Define use of pins
pinMode( RED, OUTPUT);
pinMode( GREEN, OUTPUT);
pinMode( BLUE, OUTPUT);
}
void loop(){
// This function runs repeatedly
int DWELL = 500; // Everywhere in the code that says DWELL will be replaced by this number.
int pin = GREEN; // You can change this to RED, GREEN, or BLUE
digitalWrite(pin, HIGH); // Turn on
delay(DWELL); // Stay on for dwell time
digitalWrite(pin, LOW); // Turn off
delay(DWELL); // Stay off for dwell time
pin = BLUE; // Redefine this pin a different color than the one above
digitalWrite(pin, HIGH); // Turn on
delay(DWELL); // Stay on for dwell time
digitalWrite(pin, LOW); // Turn off
delay(DWELL); // Stay off for dwell time
}
Press the Upload button to send the code to the xSystem. Once it has finished uploading, the CW01 should be flashing its LED green, and blue.
This simple lab shows us how we can command electronics using a software program. Check out the Deeper Understanding section below to get some important explanations behind what we are doing.
Continue to Lab 1!
You can imagine that a variable is a labelled box that can be large or small and holds either letters or numbers.
We only need to tell our code what variable type (box size and type) we are using once. Some variable types that we will use throughout these lessons:
-
int
Stores a small number without decimal places -
float
Stores a large number with decimal places -
char
Stores a single letter -
string
Stores a sentence
We can tell our program what kind of variable we want by initiallizing or defining it. If we follow our box simile then this example:
int variable = 5;
tells our computer that our box will be labelled 'variable', it will hold an 'int' (small number), and we want to put '5' in that box.
Later we can say something like:
int variable = 5;
variable + 10;
and get 15
for an answer.
TRY IT: Change one of your
pin
variables to equalRED
.
int pin = RED;
TRY IT: Change your
DWELL
variable to equal1000
.
int DWELL = 1000;
Hardware refers to all the physical pieces of our xSystem electronics, like the lights, connectors, processors, and switches. Many of the different hardware pieces are very small and interconnected inside the chips.
Software is the sketch that we write in the Arduino IDE. When we press the "Upload" button, our computer sends electronic signals to the xSystem processor, which then remembers new instructions and executes them using its connected hardware.
The fundamental connection between hardware and software here is that the Arduino IDE will convert our sketch into a series of signals that are sent over USB to the IP01 xChip, which then carries the message over to the processor in the CW01. The processor reconfigures its memory with the new program and runs it by sending new signals to different electronic components.