Michael Edwards: Fab Academy 2019

Week 15: Networking and Communications

2019.04.24

Individual Assignments:

  1. Design and build a wired and/or wireless network connecting at least two processors. Incomplete
  1. I2C Basics
  2. item2
  3. item3

I2C Basics

What is I2C anyway?

I2C is pronounced I-squared-C. The name is a stylisation of Inter-integrated Circuit (IIC). It is a serial computer bus for transferring information between microcontrollers. It is a multi master and multi slave system. It is syncronous (synchronised by a clock signal),

The design uses two bidirectional 'open collector' lines: Serial Data Line (SDA) and Serial Clock Line (SCL). They both have pull-up resistors so LOW is used to output '0', but HIGH is not actively driven. It just relies on the pull up resistor to output '1' after setting to the pin to float (high impedance).

Back to the top

Preparing the boards

Hello.world

I had two or three hello.world boards lying around after that week - I made some extra to practice soldering and because some needed extra work like jumper wires.

I connected two boards back up to my laptop and programmed them (one at a time of course). I'm going to do a simple I2C exercise. I want to press the button on one board and have the light work on the other board. I wanted to make this the simplest it could be and make sure it works and that I understand it. Then I want to have a go at making the accelerometer work.

The SCL and SDA line pins on the ATtiny44 are PA4 (SCL) and PA6 (SDA). Both of these are traced to the ISP header.


				Code
				

I got as far as writing a sketch using the Arduino Wire library and tried to uplaod it to the ATtiny44. the Wire library does not work with the ATTiny family. I went back to the internet for some more reading and discovered TinyWireS - an ATtiny44 library. [Credit Required]

The 'libraries' folder inside your sketchbook (File > Preferences > Sketchbook location). I then extracted the downloaded TinyWireS .zip file to that location. The extracted files had an extra layer of folders, so I copied the TinyWireS folder from inside the wrapper folder and pasted it straight into the 'libraries' folder. Now in Arduino IDE I can choose TinyWireS in the library list. It appears in the contributed libraries list.

I read the readme.txt documentation and any forum posts i could find. One said the functions in the library were the same as Wire, just replace it with TinyWireS. I tried this and the code would not compile for the '44.

So, back to reading - all of the above only takes a couple of seconds to read, but in real time I am now a few hours in and getting a bit frustrated. Des looked through Fab Academy for me and found a succesful implementation of I2C with ATtiny44s. Filipa Silva from FabLabFCT in 2017 had managed to get it working. I was pleased to see she had followed a similar route to me and used the TinyWireS library, but had gone one step further and used a different library on the master.

The mistake I made was missing the significance of the 'S' on the TinyWireS. It stands for 'slave' and is only designed for the slave device.

Final Project Testing

Adafruit MMA8451 3-axis accelerometer

The rocket will need to report its postition. The Adafruit MMA451 3-axis accelerometer (3AA) can detect motion, tilt and basic orientation digitally.

To connect the Arduino Leonardo and sensor together I have simply connected SCL, SDA and supplied GNd and VCC to the sensor from the Arduino.

I then downloaded the the Adafruit library for the 3AA module I am using from here. I also installed the Adafruit Sensor Library from here.

References

Online