Exercise: Chip blink

Objective

Make a LED blink using the Chip computer.

The Chip is a low-cost computing platform similar to the Raspbery Pi (Check in the Comments section for a discussion about the similarities and differences between the two). The Chip has built in wifi and runs linux. Since the Chip runs linux (and since there are good libraries), we can write all of our code in Python.

Next Thing Co. (NTC), the makers of the chip have created a great documentation page, that they will be adding to as the Chip and its software and libraries evolve. Check it out here. We also have a couple of NTC's Pocket Chips, which are a cool add on for the chip that gives you a portable, battery powered linux box with a built in screen. If you want to play around with one, talk to us.

Since the chip runs linux, we will be interacting with its command line quite a bit. If you have never used a command line (or terminal in Mac), check out this series of games that teaches you important command line skills: http://overthewire.org/wargames/.

Steps and observations

  1. Before we can start writing any code, we need to get our chip set up.
    1. First, we need to get the correct operating system on the Chip. If you are the first to use your chip, you should already have this. If so, you can skip this step. If not, head over to the flashing documentation and flash your Chip with 4.3 GUI. If you have a computer with only USB 3.0 ports (ie. any modern Mac), you will need to use a USB 2.0 hub or the flashing will not work.
    2. Power the Chip from the USB-micro connector. Make sure to use a USB power supply (one of the 2.4A ones from lending works well) and not a USB port on your computer (computer USB ports can't source enough current). Using one of the component to HDMI converters, plug the chip into a monitor, and use a USB hub to attach a keyboard and mouse to the CHIP. Once booting up, click on the network symbol in the top right and connect to a wifi network (the lab network will be the easiest to connect to on campus).
    3. The rest of our setup will be done on a command line. You can either keep the Chip plugged into a monitor and open up a terminal or you can ssh into the chip. To ssh, you will have to find the ip address of the Chip. To do so, open up a terminal run the command: ip addr show wlan0. The ip address will be on the "inet" line. Next, on a computer connected to the same network as the chip you can ssh using the program of your choice. For PC, check out Putty. For Mac, the ssh command is the easiest. Just open a terminal and type ssh user_name@ip_address (ex: ssh chip@192.168.1.12). No matter how you ssh in, you will need to use the username "chip" and the password "chip". If you plan to leave the chip connected to the internet for extended periods of time, make sure to change this default password, or you may get hacked.
    4. Install the CHIP_IO python library (Follow the instructions for Python3 as we will be using the python-osc package again). If you are asked for the sudo password, it is also "chip".
    5. Install NTC's fork of the Adafruit GPIO library. This will allow us to write python code that will be easily portable between the Raspberry Pi and the Chip. Use these commands to install the library:
      sudo apt-get update
      sudo apt-get install python-smbus
      git clone https://github.com/xtacocorex/Adafruit_Python_GPIO.git
      cd Adafruit_Python_GPIO
      sudo python3 setup.py install
    6. Now we need to get our code on the chip. You can find the example program here. To get this file (and files you will be writing yourself) onto the Chip, you have 3 options:
      1. Open a web browser on the Chip and download the link on the chip.
      2. Open an editor on the Chip and type out the code. If you want to do this in the command line on the chip, type nano your_file.py in a terminal and it will open your_file.py (or make it if it doesn't exist). Nano is a basic command line editor that acts a lot like a regular text editor. To save your file, type control-o and thne hit enter to confirm the file name. Other commands are listed on the bottom of the screen (hit control and then the letter listed to execute the command).
      3. Transfer the file from your computer to the chip using scp. Scp is a terminal command (or for PC's, a program called winscp) that allows us to transfer files between our computer and the chip. This allows us to edit files on our computers and then just move them to the chip for testing. The format of the command is: scp source_file destination_folder. It will copy the source_file to destination_folder. For easy reference, here are the two commands you will most likely be using (for reference, path is just the "address" of something in your file system. For example, if you want a file called my_file.py in chip's home directory, the path would be ~/my_file.py):
        1. Move file on your computer to chip:
          scp {path_to_file_on computer} chip@{your_chips_ip}:{path_to_folder_on_chip}
          ex. scp my_file.py chip@192.168.1.8:~/ moves my_file.py from current directory on your computer to the chip's home directory.
        2. Move file from chip to your computer:
          scp chip@{your_chips_ip}:{path_to_file_on_chip} {path_to_folder_on_computer}
          ex. scp chip@192.168.1.8:~/my_file.py . moves my_file.py in chip's home directory to the current directory on your computer.
    7. Once you have the code on your chip, build the circuit below and then run the command
      sudo python3 chip-blink.py to make the led blink.
    8. If you want to change which pin the LED is in, just change the variable in the python sketch. Just be forwarned that some of the pins cannot source much current (not even enough to drive an LED). You can only tell they are working if you block out most light and look very closely at the LED. However, they are probably strong enough to drive a MOSFET. I believe this issue is just on the pins that start with "XIO-P".

Comments

The Chip and Raspberry Pi are both small computers that run Linux on an ARM processor. However, they both have advantages and disadvantages that you should take into account when deciding on which to use in your project. First up, cost: the Raspberry Pi is $30-$35 while the chip is only $9. You can borrow both for free from either IDeATe or the class supplies, but the cheaper price means that frying a board on accident has less of a consequence. Next, the camera: the Raspberry Pi has a great camera module that your can also borrow from IDeATe that makes computer vision fast and relatively painless. The chip does not have this. Finally, advantages for phys comp projects: The Chip is smaller than the Raspberry Pi. This, allong with the Chip's symetric headers make it nicer for embedding into a phys comp project than a Raspberry Pi. Additionally, the Chip has a plug for a LiPo battery, and it handles all of the charging for you, making adding a battery to your project fairly easy.

Other Files

  1. Chip-blink.fzz
  2. chip_blink.py