Embedded Programming
18 October 2017 | By Casey Evans
“The ones who are crazy enough to think they can change the world [of loads of electrons] are the ones that do [or at least try]” -Steve Jobs [Casey Evans]
Assignment
Class Notes
Other People
Yun made a bike. Could add to to make it the final project. Kate Weishaar went last time. Yanru Wang. Awesome flexure commentary. “Beautiful and a real pain” -Neil. She did some of her own cardboard flexures, they’re pretty great. Actually she’s got lots of cool stuff. She proved OSB isn’t good for flexures too. Comment: in nice wood you can just kerf to make a nice flexure. Don’t forget about chamfering. I could have done that with my cat. CAD->CAM->machine control. Final project – intergeneration communication. Esp8266 wifi module (power pigs, not good for battery) – can use for web services. Bluetooth 5 modules, BlueNor. Glowing display that looked like the sea shore (an old project mentioned by Neil). Someone also made an inflatable robot. And mold/cast silicon. Keitaro Bando made a table. Pull parts to nest for fabrication can be done in Fusion. Dwg and dxf are evil – not real formats. They are storage used by Autodesk and inconsistent. In 2D svg is good. Know when to do vector not raster. Tool to workflow without intermediate Xdesign->mods. Sand, seal, paint OSB to make it really usable. Raphael Schaad’s Cocoon. Pick one function to focus on (a lamp that adapts to the lighting around it). Vik Parth. Dog bone fillets (I think it gets sharper edges with an endmill. In Antimony you can see the part definition, the part and the way it fits with other parts all in one window. With better wood it wouldn’t have worked but “OSB is so homely you can kind of just mush it together” -Neil. “Once you’re spun up on this it’s as easy ask laser cutting.”-Neil. Vik is making glasses. Laser picoprojector “cheap and cheerful”-Neil. Modella does metrology down to the micron to make lenses. James Pelletier. MIT spectroscopy lab helped to invent quantum mechanics using the help of a ruling engine (diffraction grating). Flexural reduction on Modella. Pinar’s crib is “on the way to being a final project” with communication and lighting or something. Self rocking dependent on baby’s sounds (recommendation by SolidWorks guy). Topography “flit milling” Diana Yan. She made a tray and a desk. USB A to USBG Sean Hickey “don’t do this project during sponsor’s week.” Megaprocessor.com is a great site for looking into computer architecture. Microfluidic bubble logic, Manu Prakash and Neil Gershenfeld.
This Week
Pre-Class Notes
Cat is a book shelf not a book case. Solid Works – Windows dependency. Xdesign uses Catia (which is used to create jumbo jets). Today’s guest speakers are Sal Lama, Solid Works Xdesign team and Milos, his partener. Beta 3 to Beta 4 coming soon. SolidWorks.com/Xdesign. 3DSpace, where all data is. Xdesign is modeling. No installation required, works in any browser. Mobile?? Design guidance is the cool addition to classic CAD. Don’t know shape but know constraints. You can add loads and direct them, can download stl directly from a load modeling simulation, can tell it not to fill certain areas, computational solid geometry (developer level speak), Catia with Boolean, equations and algorithmic geometry not there yet, part of beta testing is providing feedback. Sean and FabLab Connect opens mods and you can send a face to mods (svg – scalar vector graphics), mods can do very fancy extraction of parts from Xdesign, Xdesign v OnShape and Diffusion, suggestion from Agnes: making flexures and fabric textures (a solid object that you can make flat somehow – origami like?), Denver Airport doesn’t fit well in traditional design workflows, SolidWorks Altium, 3D surfaces to fold out – another step to sheet metal, generative design (desirements – requirements you want but can’t have) specify goals and constraints, Will is working with these guys (TA Will) and Neil can also give us their contact information, Neil will make an issue traker for Xdesign feedback.
Admin Notes
Don’t mess with conferences on the 6th floor. Close out issues when they finish. Jia Bao Li suggests ffmpeg and avconv media converters. Demo videos a few MB not 10s of MB.
The rest of the notes
Read a microcontroller datasheet. I’ve done it. Not for the ATTiny though. I’ll give it a good once over though. I’m tempted to get an MSP430 but the struggle is actually more just how to program the thing. I’m not sure why I don’t know how to do it. Is it supposed to be intuitive. All I need to do is mess around with programming it in a few different ways. The time has finally come. Embedded programming takes time to master. Harvard architecture, aiken bug computer (literally a bug crawled into the computer). The computer is in the science center. Faster and more predictable, they don’t modify themselves. We use these in microcontrollers. The program can modify itself in von Neumann. CISC vs RISC. RISC is faster and more consistent. Microprocessor computes. Microcontroller integrates features into one central chip—less capability but pretty efficient. Registers to execute operations, static memory to read and write quickly, dynamic memory is compact but harder to access. EEPROM, fuse memory. Peripherals-don’t compute but it’s something the processor uses to communicate with the outside world. 8 bit. 64 bit for computers. But big word sizes aren’t more powerful – it’s more about speed. 20MHz – one audio sample gets 1000 instructions so easy to do 64 bit math on an 8 bit processor. 8051 is an ancient architecture we won’t use for anything. PIC is a CISC. ARM is a soft architecture. PSOCs have programming around them (between microprocessors and FPGAs). We’ll focus on AVRs (owned by Atmel and bought by Microchip). They were made by two Norwegian grad students who wanted modern compiler/software development (RISC) capability. Cheap with great performance and tons of available packages. Octopart helps sort through vendors. Digikey is not the cheapest but it is the most convenient. V grade is for low voltage (on AMR). Loads of tutorials online. The different packages on the datasheet have different amounts of memory. TSSOP and SOIC are what we’ll be using.
Clock subsystem. Resistor and capacitor charging and discharging. Good to about 10%. Can calibrate it to 1%. Ceramic is good to 0.5% Phase locked loops (PLL) – system clock at a different speed than system. You can overclock the thing with variable results. Use the instruction set. It shows the number of clock tics per cycle. Ring oscillators – pub.pages.cba.mit.edu/ring/. Raspberry Pi runs at kHz. Good ones run at MHz (go out read a pin, write to a pin, read that pin, and so on in a cycle – one cycle is the period). Load a program into the processor. ISP header is for loading in program. Clips, pogo pins. V is where is reads the voltage on the target. Reset is pulled high normally except when getting programmed. MISO/MOSI communication between processor and host. Check out memory programming. I don’t know why I feel so incompetent, I’ve taken multiple classes on this. ISP – in system programming. Bootloaders are programs to load programs, then you don’t need the memory program anymore. Atmel and Arduino have their own bootloaders. Use the ISP to load the bootloader and then only use the bootloader, for example. Brian is the person who made the Week 3 tutorial. AVRDude is help on programming. Read a pin and blink a light. Go to data sheet. Tell button pin to be an input, tell LED to be output. Each group of pins is a port. Machine code! Assembly language – each line is one instruction. C compilers (from Bell labs) above assembly but not a high level language. Learncodethehardway.org and another good link on the class page. GCC is a good modern compiler. gcc.gnu.org. AVR-libc for C to AVR and GCC calls that. There’s an Atmel studio for Windows (compiler). “Nobody writes these type of programs from scratch. You take them from something you did or someone else did and modify it for your purpose.”-Neil. “Arduinos are a subject of great confusion.” It’s a set of boards like Uno, set of libraries, IDE, bootloader and form factor. First, load bootloader with ISP. Arduino is using C with a set of libraries (there is GCC behind the environment). Arduino adds a lot of performance overhead (factor of 100 or more). Not efficiently written. Slow down clock for battery to last longer. Macro is a short hand or convenience (ex. #define such and such a thing). Encapsulation and abstraction. Loads of abstraction in Arduino libraries. Connect two pins, write a pin out and read it (ring oscillator). I could test my board with Neil’s code before moving on to messing with the LED and button (and buzzer). 9600 bits per second – serial communication. USar using a subsystem versus the main system. If I’m working with something I want to plug into the wall I should use a surge protector. Just in case. You can have your program print error messages to you. Bit bagging – turning bits on and off to do the job of a communication system. LUFA, you can emulate a mouse or keyboard or something. Make your own cable. Using interrupts. I will use that for the IR receiver. Asm doesn’t need a compiler. IDE is a GUI-they aren’t better they’re different. highlowtech.org on course site. ATSAM4S. Booting an operating system would probably be something you buy, not make.
Training Summary
None. Just be smarter.
Assignments
Individual Assignments
Okay. I’d forgotten that I’d used another board to program my board. That’s what you get if everything is already set up once you get there. I’m going to try Atmel Studio first.
I told Atmel that I was using an ATTiny45, which confused me and it for a good while until I switched it to an ATTiny44A. I found out that the problem was just selecting the wrong device in Atmel studio (ATTiny45 when I was trying to write code for the 44A). But I'm now having issues with connection. It was connecting before and it still connects to other computers but it doesn't connect to my computer. Is it something I installed or what else could be the problem? By "it" I mean the programmer (the ATTiny45 circuit from Brian's site). My programmer stopped getting recognized by my computer. It had been off and on due to my computer’s unreliable ports but now it’s just not working at all. Joy. I’m going to restart my computer. Just in case. Dang it. It didn’t work. I wish I had another computer to try it on. I found a Mac in the lab and subversively plugged in my programmer. The Mac was able to identify it, so I know it’s okay. I think I’ll try to load a program through the port and see what happens. I tried to connect with step-by-step from this site. I also tried this (SPOILER ALERT: none of those were any good and I ended up using this with success instead.) I’m not sure what’s up but I’m pretty confident the program will run. Partly because I just have someone else’s test program but also because it’s a very basic light blinking program. Not sure why it won’t connect. I tried on my computer a few more times and then got paranoid and tried it on a friend’s computer, where it worked instantly. I think I’ll just use one of the lab computers again. What a pain. I installed WinAVR thinking it would magically solve the problem. It didn’t. Haha, after refreshing the Device Manager page a few times I got it to connect! It was under “Other devices.” But now I feel too lazy to walk back to the lab. One, two, three! It still doesn’t know what to do with itself though. Maybe this will help: link. It makes sense but I’m not sure if its suggestions will be helpful. Andrew Mao led me to this link which seems like it should work but I get: avrdude.exe: Error: Could not find USBtiny device (0x1781/0xc9f). No fun. I finally gave up and tried it on the Ubantu machine and again it didn’t work. Gavin suggested there was something up with the reset pin so I checked using a multimeter and VCC was at 5V, ground was at zero and reset was pulled high. I think that’s how it should be before programming. I’m not sure what is up. I also tried with the AdaFruit programmer and had no luck there either. So the guess is that something is wrong with the ATTiny44A board itself but I don’t know what and I’m out of ideas. I will have to wait to ask more TAs for ideas. Sometimes I wish I could be smart enough to solve every problem. Other times I wish to ignore the problems. Of course, I still want to solve them but when I see how everyone else seems to approach them and slice through them it makes me wonder what the point is anyway. Why even bother if I’d never be good enough at anything to contribute to a project anyways? I will forever just be the person in the way. Maybe I’ll find something I’m good at one day. But there will always be someone 100x better at it than I am so there’s no point in even trying to figure out what that could be. Hmm. I guess it’s time to flush out the blog as thoroughly as possible before tomorrow and hope to not get called on. I’m sure I’ll figure it out but I’d rather find a debugging partner than wallow around in all of this stuff I barely understand any longer. And I get it, I should have planned ahead for this. But I didn’t because I’m a pathetic loser and there’s nothing I feel like doing about it now. Debugging partner come to my aid, I’m a useless piece of slime!
This is the place to get the toolchain (not the link in Brian’s thing). This is the toolchain release note. That was all a lie. I don’t understand those websites. I just used the toolchain installed along with Atmel Studio and copied it to the folder where Brian had it. For your convenience, I've put it here. Let me know if it doesn't work for you, because I'm not 100% sure it copied the files correctly.
And I finally made it through the Windows setup tutorial! But the programmer I brought home with me from the lab isn’t taking power anymore (I tried it on another computer too), so I get to postpone again. Next round of “how does this work” is: (1) I think I’ll need to disable the reset for it to work properly as a programmer. I was going to try not to do this but based on Gavin’s comments I think that is my problem. (2) Learn about the programming process. I’m used to plug-and-play with established protocols and such from commercial/designed and set up for a class projects. I have a c file I want to test, but I’m under the impression that I need to do something with “make” or have some kind of make file. There’s probably some resource on the course site but I’m not finding it. (3) Try all the fun programming things I wanted to get to. Blinking light – button press light – anything from the buzzer besides it exploding.
Update of the morning. The programmer decided to accept power again but the board won't do the restdisbl. Either it's because it's already been done (and I don't know how to check that) or I have the ISP header upside down. I'm nervous about frying the board so I won't flip it over until I have a multimeter to check. Or I'll just make another board that I can see and manipulate (and know for sure where all the ISP lines go).
So I went to the lab and tested the pins to find ground and power (ie the right orientation). Turns out I did have it backwards but that didn't solve the problem immediately. I switched to the Ubantu machine in the lab and still wasn't having luck so I put a piece of double sided tape on the bottom of my programmer without removing the plastic covering the second side. This made it a bit thicker and it had much more reliable computer connection. That should have been one of the first things I tried. I'd noticed that if I held it a certain way it would connect and sometimes moving it around would disrupt that. That still wasn't a perfect solution so I actually soldered the VCC to VPROG connection (before I'd just been using a wire held by hand or an ammeter on either side). Then it finally ran the reset disable! Check out that gorgeous screenshot:
Once I did that it was very easy to load the program from Atmel Studio using my program on, get this, my computer! Wow. Super sweet. Check it out.
The light blinks like it's supposed to (in the debugging I'd replaced my program with a tried and true one from Tinysaur. So now I'll make my own program. Oh and just so you know, you can unplug the programmer once your board is programmed, you just can't unplug power. I'll have to look into how you can keep power on the board (ie connect a battery) for final project era stuff. Here's the video of the light:
I used ClipChamp to convert and compress the video.
The other programs I've made come up mostly in output devices week. But I also did some work in the final project and scattered throughout the whole semester.
IN SUMMARY: Go to Brian’s site and follow the instructions. If you’re using Windows, use Brian’s guidelines except for getting the toolchain, which you can instead get here (though I'm not 100% everything copied properly). I like Atmel Studio (unfortunately just for Windows apparently) alright and just follow these instructions to get it to work with your USBTiny.
Group Assignments
None