Networking and Communications
29 November 2017 | By Casey Evans
“A brand is no longer what we tell the customer it is--it is what customers tell each other it is.”-Scott Cook, founder of Intuit
Neil says that the point of this class is to get rid of the sentence that “I’m MechE so I don’t know how to program.” As well as “I’m CompSci so I don’t know how to make.” But all this messy compsci guru stuff is intimidating.
Work not by demand on your time but by the supply of your time. Recitation one floor down. Sam will cover the XMega. PSoC. Processor core with soft modules around it. Arm programming. Build a wired or wireless network connecting at least two processors. Many reasons for this. The obvious one being talking to something that’s not where you are. Another is an interface on a device for a device somewhere else. Parallelism. AVR runs at 10s of 10^6 cycles per second but costs 10s of cents. Also can help with performance. Modularity is another good reason (separate subsystems to test independently). Interference. One circuit with high noise and all that is hard but if you have separate boards for each system then you can limit interference. Start with simple networks and end with radios. RS-232. Extensions for multiple devices. Bridge board, Tx and Rx lines onto a bus. Tx to Rx. Each board connected to the Tx and Rx lines. Tristated Tx. Give an ID to each board. Each board listens but only one board matches the message, when it hears its ID it changes to an output and sends a message. Simple serial bus for no more than 10 processors probably but they should be pretty easy to understand. “It’s really trivial to make a serial bus.”-Neil. Have to be well behave to take turns talking. I2C is a standard protocol. RS-232 is asynchronous, you just blurt out the data. I2C has a clock line as well as a data line. It’s a standard protocol for interprocessor communication. Prioritizes who gets to talk. Accelerometer speaks SPI or I2C. Atmel has app notes. TWI or USI modules. TWI is the same thing as I2C (Philips IP battle). Bit banging it where you use software to turn pins on and off. Programmer speaks SPI. Roughly equally useful SPI to I2C. SPI in circuit programming, I2C device networking. Sociotechnical history no deep reason. SPI is faster at really high speeds. If he controlled both sides Neil wouldn’t use either. USI section of the ATTiny44 data sheet for more info. V-USB is USB in software. An extreme version of bit-banging. It’s slow (USB 1.0) USB has tight timing requirements but it adaptively clocks in software by listening to the host. USB to FTDI project has been done. With MegaU2. LUFA is a good third party library using AVRs with hardware USB to implement various devices. Bus v network: network designed so anybody can talk to anybody and (ideally) know where each other are. Mac how you decide who can talks…oh, there’s loads of OSI layer.
Modulation: PCM (pulse code modulation), PPM (where the pulse occurs), OOK (presence or absence of a signal), FSK (two freqs, one for zero or one, needs a radio for more than one freq), PSK (change phase, only needs a radio at one freq but you need a reference local source to understand), QAM (phases and amplitudes to store lots of bits), spread spectrum (modulate to look random), DSSS (uses random noise), goal is to use bandwidth as effectively as possible, The Comminications Handbook by Gibson.
Channel Sharing: who gets to talk, Aloha you try and if you collide you try again, master-slave has one person tell when to talk, token ring token can get lost, CSMA how wifi and ethernet work (cocktail party, listen and if someone else is talking you don’t talk, pause in silence for a random backoff time before starting to talk; fails if network heavily loaded), CDMA (spread signal to not interfere with each other), MIMO (antenna thickets to steer the beams to get them spacially localized).
Error correction: expect to make errors so add redundancy.
Networking: there’s a good book on it, he’ll fix the link, topology to get from one point to another, internet engineering task force, IPV4 moving to IPV6, packets have a structure and IPv6 has a larger address space, NAT reuses addresses, unrouted private space you can use and assign yourself, IP is address on a letter, UDP adds ports (rooms in the building), TCP splits a big message into small messages, http is tcp to port 80, telnet, sockets are a standard protocol, JS and Python easy to talk to sockets, C is harder, IP over serial dates back to modems (Slip)
Radios: ARRL Handbook, oscillator to send signal, mixer to modulate data, low noise amplifier to receive, intermediate freq stage for partial amp, intermediate signal, filter baseband data. Picture a heavy chain and a skinny thread connected, vibrating thread will reflect back—illustrates need for impedance matching. Antenna gain focuses energy. Single chip radios. IS1871. BLE. System in chip. ~$7. Speaks a simple protocol. Antenna is happier if there’s nothing underneath it. Speaks simple serial. Nordic BLE sniffer. Castellated so pasted on the side of the board. Standard services. Event driven model. nRF24 has all kinds of great parts mixed in. nrf52. Care about it because it’s a very fast ring oscillator. Good radio performance. It’s a general-purpose processor that happens to have a radio. Sam is writing a page on using the nrf52. Requires a new toolchain and all that. Long term goals. Wifi is a power pig. 100s of mA. Requires a big regulator. TCP can go in either direction. Software radio – bit bang radio in software.
Takeaway – at least get the serial bus. Aim it at your final project. Not enough for everyone to have every one. ARM programming, nontrival learning curve.
None. But I did go to recitation this week.
So. I got my hands on a Bluetooth module. But that's about it specific to this week. I also spent time working through getting the serial connection to work (see week 12) and cleaning up my output week to be a bit cleaner and better documentation. But the real culprit here is the massive paper due this Friday that has taken me more hours than I'd admit and is still only 11/20 pages in the works and my signal processing project (where I was able to write 11 pages in only a few hours, go figure). Point is, weeks 7, 9, 11, 12 and 13 are all kind of intermeshed for me right now and I will be taking the weekend to sort them out (after the paper, project and pset have been turned in and forgotten).
So it turns out the module I grabbed (the nRF24L01+) really doesn't do BLE as I thought it would. Or if it does, the datasheet isn't very helpful with it and I, with my limited experience, would not be able to pull it off in a reasonable amount of time. So I grabbed a RN4871. This chip wants 3.3V when using FTDI, so I'm thinking to just make a step down voltage divider so I can keep using my 5V FTDI (which I need to buy off Gavin or somehow otherwise aquire). But I'm not sure if the Tx and Rx lines will complain about that. I think for the Rx line I'd have to make sure that the 3.3V will pull up to 5V on the other end. Maybe I only need them to program though in which case I don't need to worry about anything except power, which the voltage divider should work well for. Next step is to read the datasheet so I'll let you know.
Okay, so the User's Guide is here. The other link is the datasheet which wasn't especially helpful. But moving forward I can't find a 3.3V FTDI so I'll try to make it 5V compatible with a voltage divider and an opamp. It's been a while since I've used opamps but here's a simulation I did to see what I would need from the BLE Tx pin to the FTDI Rx pin:
The ground can be common and the Vcc and Tx from the FTDI can be stepped down with a voltage divider. The datasheet says it can operate from 1.9V to 3.6V so a 499ohm and 1kohm voltage divider (the parts available) which gives about a 3.33V output should be fine. I did a simulation to check:
In order to figure out the configuration of the opamp I needed to use a pin diagram. THe one for the fablab opamp is shown below:
Now to draw up a board and print it out. Also, just for reference, I like this version of the fablab inventory. Right now I'm reading through the BLE documentation for App Inventor. I think the way this works is that I could send the BLE commands from the app and then write to the Tx line which could go to the Rx line on the ATTiny controlling the LED bulb. Not totally sure there. I just ran that by with Natalie and she said that's pretty accurate. I can also use GPIO pins. It took me a bit to get the layout working for the modified 5V FTDI compatible chip (at least, I hope it's FTDI 5V compatible - I worry that the BLE Tx line might get pulled up by the opamp but I don't think it will matter too much - at worst it will bring it to 3.3V probably which the 3.3V FTDI would have also done). Well see. I'm an experimentalist and the time has come to try. Actually, I not really either but I think I should just try it rather than worry about it. Well I machined it and the size is just ever so slightly/majorly off that it won't work. And I accidentally ended Priyanka's job while it was calculating so I'm letting her have a turn while I debug. But Niki had a 3.3V cable so I'm going to just try using Neil's native board first then. If it helps my almost board was:
Remember that the scaling is a bit off for the parts that came from Neil's board originally. The parts I ported from Eagle were scaled as I set them. Oh well, that would take time to fix. I'll see how the original board works with a 3.3V cable. I did find the ratio Neil's parts were off by at 1000 dpi. It should be 0.614585 in tall. So I tried that and it was giving me funny issues with the traces so I left it at 1000 dpi and had the same problem. Geez, I gotta learn from my mistakes. And the lab's closing again so I'm going to go home and get some CADing done for tomorrow (bulb, lampshade, stand) and maybe start working with App Inventor. I may have to tell my advisor that I can't come in tomorrow morning. I dunno. Such stress. Very wow. So I did a lot of sketching out things and
Okay, so after much troubles I was able to build the Bluetooth board Neil laid out. Looks great, right?
I plugged it into my computer with FTDI and was confused for a bit until I read the user's manual a few times with Mike. I used PuTTY as a terminal simulator to talk to the thing. After a bit of flopping about I discovered typing $$$ into the terminal gets you into command mode with the BLE. After that you can type commands and hit enter to send them to the device. A good start is the command '+'. That activates echo so you can see what you're typing. Then 'SS,C0' enables the 'UART Transparent service' which is basically how the thing works. You can name your device with 'S-,string'. I called mine ILoveLamp since that's what my roommates have been calling it. Microchip has two great apps for development: SmartDiscover and SmartData (which you need to search in the app store with "Bluetooth Smart Data." These are Apple apps. They look like this:
I'm not sure if they have Android equivalents. The first one finds your device and the second one is a little terminal where you can send messages back and forth. I did that a bit. Nearby BLE devices come up on your screen like so:
Then you just tap to connect. And you get a screen like this:
And when you change the name of the device with "S-,name" it can look like this (note same UUID):
You can send the device data via the SmartData app. I sent a few messages that came through. This is the PuTTY terminal simulator output of what I sent:
Then I tried out the pin setting in the command line. The pinout of the RN4871 is:
I was switching pin 1_2 which you can do with '|O,08,08' to set and '|O,08,00' to reset. There's a table I still have to see if I can enter command mode from the phone terminal, figure out how to send things back to the phone (ie get to the serial terminal of the device) and how to get it to work with App Inventor. I think my networking segment might be to connect the Tx on the BLE to the ATTiny just to see hello echo, but I'll look into that when I have a working lamp. Okay, so sending it '$$$' via the app doesn't cause it to go to the command mode.