107 iPS Andrew Talks Arduino

Download MP3

01:47 - An Arduino is a Microcontroller

03:46 - Where Do You Get an Arduino?

05:00 - Getting Started (Equipment)

07:58 - Language/Interface

13:07 - Raspberry Pi vs Arduino

16:30 - iOS Compatibility

24:12 - Projects

32:24 - Patterns

34:41 - Debugging


The 7 Day Startup: You Don't Learn Until You Launch by Dan Norris (Alondo)UIKonf 1995 Keynote: Object-Oriented Programming in Objective-C (Andrew)AmScope SE400-Z Professional Binocular Stereo Microscope (Andrew)Charlie Christian Neck for Telecasters (Jaim)


[This episode is sponsored by Hired.com. Every week on Hired, they run an auction where over a thousand tech companies in San Francisco, New York and L.A. bid on iOS developers, providing them with salary and equity upfront. The average iOS developer gets an average of 5-15 introductory offers and an average salary offer of $130,000/year. Users can either accept an offer and go right into interviewing with a company or deny them without any continuing obligations. It’s totally free for users, and when you're hired they also give you a $2,000 signing bonus as a thank you for using them. But if you use the iPhreaks link, you’ll get a $4,000 bonus instead. Finally, if you're not looking for a job but know someone who is, you can refer them on Hired and get a $1,337 bonus as thanks after the job. Go sign up at Hired.com/iphreaks]**[This episode is sponsored by DevMountain. DevMountain is a coding school with the best, world-class learning experience you can find. DevMountain is a 12-week full-time development course. With only 25 spots available, each cohort fills quickly. As a student, you’ll be assigned an individual mentor to help answer questions when you get stuck and make sure you are getting most out of the class. Tuition includes 24-hour access to campus and free housing for our out-of-state applicants. In only 12 weeks, you’ll have your own app in the App store. Learn to code, it’s time! Go to devmountain.com/iphreaks. Listeners of iPhreaks will get a special $250 off when they use the coupon code iPhreaks at checkout.] **JAIM: Hey everybody and welcome to the episode 107 of the iPhreaks show. This week on our panel, we have Alondo Brewington. ALONDO: Greeting from Goldsborough. JAIM: Andrew Madsen ANDREW: Hi from Salt Lake City. JAIM: And I'm Jaim Zuber from Devchat.tv. Wait. No, I'm not from there. I'm from Minneapolis. We don't have a guest today but we've got – Andrew is going to talk about some Arduino. ANDREW: Well, I hope we all talk about it. I actually gave a presentation about Arduino at our local Cocoa Heads recently so I'm going to follow that to intro. I think the first thing to know about Arduino is that it’s a microcontroller and it's meant to be easy for everyone to use. The question is: what's a microcontroller? A microcontroller is just a little – basically a computer on a chip that you can program. They're typically very stripped down. They're not super powerful. They're nothing like the CPU in a computer, even in an iPhone. They're things that are simpler than that generally. But they're good for if you want to make little devices that have smarts like robots or a sprinkler timer or even just something like a remote control garage door opener. There are all kinds of projects you can come up with. When the people who made Arduino were working on it, their goal was they wanted people who were not technical; who were not hardware engineers to be able to use microcontrollers to do cool stuff. I think, in particular, one of their ideas was they wanted people to be able to make digital or interactive art – that were artists not programmers and not engineers. I think they really succeeded at that. So the whole point of an Arduino is that you can get up and running having never programmed a microcontroller before in your life very simply. In many ways, I think it's significantly easier even than iOS programming. It is definitely easier. I think it's a smaller field. But as Arduino has grown and got more popular, I think one of the biggest advantages now is not just that it's simple, it's that there's this huge community up there, so there's a big ecosystem of accessories and tutorials and libraries that people have written. It's just all kinds of cool projects that people have gotten. There's really an open-source ethic in the Arduino community. The Arduino itself is all open-source. The hardware is open. You can download schematics and firmware for it and the things that other people have created for Arduino tend to be that way too. So, it's a really good way to get into hardware where everything’s open and you can prototype something with Arduino and actually build it for real because nothing is close to you. I think that's a good overview. JAIM: If I want to buy an Arduino, how do I do that? ANDREW: There are actually a whole bunch of different Arduino boards that the Arduino Company makes but because it's open-source, lots of other companies have made their own Arduino-compatible boards. They all work with the same Arduino IDE and programming language. I think a good way to start is with the Arduino Uno. That's the main normal standard Arduino. You can buy them on arduino.cc. I'm sure you can get them on Amazon and I actually have bought them at Radio Shack although Radio Shacks are hard to find now but the ones that are still left do actually carry a decent selection of Arduino stuff. Then, I think actually two sites for buying stuff that are really good to know about are SparkFun and Adafruit. Both of those are similar in that they sell all kinds of hardware, hacking stuff for people that want to do hardware projects. They also both have designed their own – a lot of their own accessories and even Arduino. I guess you’d call them clones, but they're not really clones because they all have a different twist. There are ones that are really small, ones that are faster than normal that have built-in Wi-Fi or built-in Bluetooth or these kind of things. So, Arduino.cc, Adafruit and SparkFun are the go-to places for me. JAIM: Okay. For some of the example projects that you mentioned, how does Arduino fit into there? It's a microcontroller but what thing is it actually handling? How do you start to setup a garage opener or whatever things you talked about? ANDREW: One of the great things that I mention is there's this a huge ecosystem of accessories. Typically, those are called shields. People have gotten confused when I've used the term “shield”. Before it is an Arduino-specific term. A shield is just a board that plugs on top of your Arduino board and gives it some other capability. There are hundreds of shields out there. But there are shields for Wi-Fi, for Bluetooth, for Ethernet; shields with various kinds of sensors like temperature sensors, motion sensors, water sensors. There are motor controller shields. A lot of times if you've got a project in mind and you know what functionality is – let's think of a garage door opener. Probably a garage door opener needs something that talk to a remote control like the thing that you have on your car. You can get an RF shield that lets you use a little remote like that. And then, your Arduino program can detect when somebody's pushed the button. That solves that part of it. You might also want it to be Wi-Fi connected so you can get a Wi-Fi shield and then, of course, you need a way to actually trigger the garage door going up and down. That might be a relay shield so you can just close the switch. One of the cool things about shields is they're stackable so you can actually just put a whole stack of shields on top of your Arduino without having to do any soldering or anything like that. You can often build up this complete system that's pretty useful just from pre-made boards that plug together. That's always a good starting point. Usually, shields also come with a library so that using them from your Arduino program is very, very simple. ALONDO: Okay. That brings up a good question you mentioned there because it’s stackable, I was thinking what other equipment would I need to get started? I've got – say, I purchased an Arduino and I have a product in mind and maybe I've even gotten as far as getting the other shields. Is it always guaranteed to be stackable or is it possible I’ll need some additional equipment or hardware to make everything work? ANDREW: Well, yeah. That really does depend on project and it also depends on the Arduino you've got. There are so many variants now. There are some that – I've got an Arduino that's like the size of postage stamp and you can't really plug shields onto it because there aren't any shield that are physically that small. You'd have to wire up an adapter. Most of the shields are designed to work with the Arduino Uno which, like I said, is a standard one. You certainly can get into situations where you need to come up with your own design with cables and solder things. But the great thing is there are lots of information in the community about how to do that out there. There are even things people have made to facilitate that like breakout boards and prototype. There's even a prototype shield where the whole point is plug the shield in but then you can build your own circuit on it. As far as other equipment beyond that, I think really all you need is your computer. The Arduino just plugs into your computer with USB and you can start programming it. ALONDO: When we start by mean of programming, what language or interface am I using to start making the Arduino do what I want it to do? ANDREW: That's a great question. There's an IDE that Arduino provides called the Arduino IDE. It's very simple – much simpler than Xcode. You program Arduino in a language that's called Arduino but it's actually very much like C. It's a simple stripped down C. In fact, I think under the hood, it's actually a version or subset of C++ but you rarely hit into the object-oriented part of it. Getting up and running, you can actually have an Arduino that boots up and does something like flash a light in three, four, five lines of code. If you've ever done any regular microcontroller programming, typically, even if you program them in C which is common nowadays, there's all this boilerplate you have to go through: setting up registers, setting up a clock divider to get the clock speed right. Just to get the thing to boot up and do anything can be a pretty big pain. With Arduino, it's not like that. You can open up a new project and hit build and run and it just runs like on iOS. There's already a template there for you to fill-in the first steps of what you want to do. JAIM: Now, is this template similar for the different types of Arduinos you can have? ANDREW: Yeah. In my experience, it's exactly the same. There are actually – we can actually talk about some of specifics there. There are actually two parts of an Arduino program that are required. If you're writing a C program, you create a main function, right? And the main function is the function that just automatically runs when the program starts. In Arduino, you don't have actually a main function. You have a function called setup and another function called loop. They're just functions that return void and take no arguments and setup gets called when Arduino boots up so that's a good chance to do any kind of setup you want to do and often you'll setup your peripherals and get things running. And then, loop is just called over and over again while the program runs so that's where you put the meat of your program. A really simple example is if you just want to flash on and off just every time through the loop, you would turn the light on if it was off before and vice versa. Those two functions, setup and loop, are the ones that are required for any Arduino program. They're the basis for even complex programs. JAIM: How often is loop called? ANDREW: I don't actually know that off the top of my head. It may actually depend on the specific hardware you're using because there is now pretty wide variety of Arduino hardware all the way from stuff with a 8 MHz clock speed up to Arduino-compatible hardware with Intel processors running it – 500 MHz or even faster. So it may depend on that. I'm not actually 100% sure. I've never used that for specific timing but I think it's pretty fast. If you have an empty loop, I think it gets called many, many times per second. So you'd want to work out your own timing not rely on loop being consistent. JAIM: Okay. So loop is called over and over again. You’re writing a function that you set to be called many times. So it's just polling and doing whatever you want to do, that's the – it's your run loop but you're not managing how fast it's called. That's all done by the Arduino operating system. ANDREW: Exactly. You can think of it very much like the run loop in an iOS program where all the input stuff is being processed. You're not actually normally responsible for spinning that run loop. Things get called for you. JAIM: What is the OS for Arduino? Is it the whole thing? ANDREW: Yeah. There's not really an OS because it's – you're essentially programming directly on the chip. An OS provides things like disk I/O and process scheduling and all that normal things; virtual memory and that kind of thing; all the things that an OS does. Arduino or microcontrollers in general are usually so simple that you don't run an OS. There aren't multiple processes running on the processor at once so there's no real need to do a lot of that stuff that an operating system does. That said, there is – it's not an operating system but, of course, this work that they've done to make Arduino programming so simple means that there's stuff behind the scenes that you don't have to deal with but it is there making things easy for you. Like that boilerplate that I talked about in a normal microcontroller, that's still required. It’s just that Arduino has written that beforehand and then hidden the complexity so you don't have to deal with it. Of course, if you do need to go down into those lower levels, one of the great things is they have not blocked any of that off. So if you're an advanced user and you want to do something that's more sophisticated than what the built-in functions give you or whatever, you can drop down all the way to the lowest levels. You can even actually write Assembly for an Arduino. I've done that in one instance. It was very simple Assembly but it was just where I needed some really precise fast timing on a pin. It's very easy. You can just write some Assembly in-line without breaking down the whole rest of your programming. You still get all the advantages everywhere else and then you can, in very targeted places, drop down to lower levels when you need to. JAIM: Okay. When you say Arduino's a microcontroller and that makes sense. How does this fit in with other similar-type systems like a Raspberry Pi. How are they different from things like that? ANDREW: Well, Raspberry Pi is a computer like the computer on your desk or your laptop and it runs an operating system. I think usually a version of Linux although I'm pretty sure now Microsoft has some version of Windows that are run on a Raspberry Pi – or at least they announced one. A Raspberry Pi would be for things where you need a lot more power and sophistication – or I should say speed and sophistication – and you don't mind dealing with the extra complexity that having an OS and all that gives you. Raspberry Pis are also more expensive. You can get cheap, really cheap Arduino-compatible hardware. In fact, I just ordered a few little tiny, really tiny Arduino boards that were – they're like $6. ALONDO: Oh, wow. Okay, because I just ordered the Raspberry Pi 2 as they came in last week and they were $35 apiece. ANDREW: Yeah. And then, an Arduino is just simpler. Look at a Raspberry Pi and look at how many things are on that board; and then look at an Arduino and there are one or two main chips and a few components around that for power. So if you're designing your own hardware – say you want to make a device and this is actually something that I'm working on now with the Wired In project that I mentioned on the last episode. I've prototyped that whole thing with Arduino but it's pretty easy to take an Arduino design and move that to a real production hardware design because it's not this hugely complex thing. It's already starting out hardware-wise very simply. JAIM: Okay. So it's useful for prototyping, things like that. Something you might want to build but you don't want to have laid-out or wire it up yourself. ANDREW: Yeah. You know it's funny. I spent a number of years as a hardware engineer and a lot of what I did was designing circuits and writing firmware for microcontrollers. When I first heard about Arduino, I thought “Well, that's for people who don't know what they're doing.” It's like the old VI programmer that doesn't want to use an IDE or something like that. Or the old Assembly or C programmer that doesn't want to move to a higher level language. I had that thinking, I thought “That's great for people who are starting out but it probably gets in your way if you're really know what you're doing.” I have to say I was completely wrong about that. So it is much like higher level programming languages where it really makes it so – even if you know what you're doing and you're an expert – it removes a lot of just tedious work that you have to do normally and the kind of mental energy that you have to expend dealing with complexity that's not there with Arduino. But that said, they haven't hidden any of that. You can dive in; you can take an Arduino design –that's a prototype – and make your own design. And because it's all open-source, you can even clone your prototype hardware. You've got schematics for everything that they've done making the Arduino. I think this is actually gaining a lot of traction even among professional hardware engineers at real companies because it's so simple and easy to get up and running. It is really great for prototyping. JAIM: It seems like they have a good balance between ease-of-use and giving yourself the power if you need it. ANDREW: Right. I think that's really important. Think about the best software APIs that you've worked with. Usually, they make things easy to get up and started but they don't get in your way when you need to do sophisticated stuff. They've done that both on the hardware and the software for Arduino. So I'm a big convert from being down on the whole idea to being a huge fan. ALONDO: So we outlined what an Arduino is and a lot of the advantages of having one and the possibility. How does this tie into iOS? ANDREW: Well, it wouldn't be really iPhreaks without some discussion of iOS. Usually, if you want to make hardware that is going to talk to an iOS device, you've really got two choices: Wi-Fi and Bluetooth 4.0. Bluetooth 4.0, of course, is only on devices that were made in the last few years but that are most devices now. I actually think that's the best way to go for most things. There is now a huge variety of Bluetooth 4.0-compatible Arduino stuff so you can get shields that add Bluetooth 4.0 to Arduino. There's actually a couple Arduinos that already have built-in Bluetooth. I've got one called an Rfduino. It's actually made by a third-party company but for the purposes of using it, it's just like an Arduino – you program with the Arduino IDE and everything else. It has Bluetooth built-in and then you can use the Core Bluetooth APIs on your iOS device or on your Mac to talk to it. There are enough people out there playing with this stuff that it's gotten pretty easy. There's a pretty low barrier to entry to doing that. The Wired In signs that I mentioned, we've got an iOS app and SDK that can control those. It was actually really a pleasant experience to get that up and running. JAIM: What does the code look like? Are we talking about a C dialect which if we're trying to get people at art tech that are not programmers, it seems counterproductive because C is not really the easiest language to learn? ANDREW: You're right. It is a C dialect. What are the things that when you think of C makes things hard for a beginner? What are those things about C? ALONDO: In memory allocation management? ANDREW: Yeah. That's a big one. That's probably the biggest one that I think of and pointers are another one. ALONDO: Oh, yeah. ANDREW: Because of the way they've designed the standard library and the subset of C they're using, you’ll rarely if ever have to deal with pointers or malloc or anything like that. Actually, that's partly because it's actually C++ under the covers. I don't fully understand what they've done to do that but I'm reading through some code that I wrote for Arduino here and it's about a 300-line program. It's nothing huge but it's doing some real stuff and there's not one place where I call malloc. I think the only couple of places where I call – where I have asterisks for pointers – are where I'm dealing with strings, passing strings around between functions. They're care stars but it’s like this. It looks like really simple at the simplest C that you could write. If you didn't tell someone “Hey, this is C.”, they probably would never – they wouldn't know just this is how you program in Arduino. I'll have to put a link in the show notes to some example codes so that people can it. There are a whole lot of examples that come with the Arduino IDE and even the pretty complex ones are quite readable. JAIM: Okay. If want to create a Bluetooth-enabled Arduino device and talk to my phone, transmit who knows temperature or something like that, how do I start – begin to setup the Bluetooth interface? ANDREW: Well, on the Arduino side, it's usually as simple as – depending on whatever shield you're using, it will have a library – it’s usually as simple as calling in your setup function, giving your device a name and then a UUID which is required for doing the Bluetooth pairing part and then just saying “Start the radio running.” And then, they will give you a callback function anytime you receive data over the Bluetooth link so that you can process that data in your Arduino. It's just a regular function that gets called when some data came in. Then, there's also a library function that you can call to send data back. So it's very simple on the Arduino side. On the iOS side, you got to do a little bit more work. The framework that you use for Bluetooth is called Core Bluetooth and there’s a little bit of effort there. It’s an Objective C API. It’s not foreign to somebody who is a Cocoa programmer. You start by scanning for devices and you use a class called CBCentralManager, I believe it is. I’m talking off the top of my head. But you get the CBCentralManager. You call scan for devices and then you get a delegate callback when it finds a device. Then you can get some information about the device. If it’s the right device – if it’s the one you want to connect to, then you can call a method to let you connect. Once you’ve connected, you can just send data to the device and then you get another delegate callback when data comes in. Getting this communication set up is pretty simple. Bluetooth 4.0 has some complexity to it for supporting various different kinds of data going back and forth. But usually when you’re working on an Arduino project, you don’t really care about that. You just want to be able to send and receive short – small amounts of your own data. That’s how they’ve – on the Arduino side – that’s how they’ve set it up. It really acts very much like a serial port or it just feels like you’re sending strings back and forth or whatever. It’s nothing super complicated or heavy. JAIM: Okay. When I was doing similar embedded work like this, we did this over a network and we would have, say, a Windows client with a C struct talking to a Linux client with a C struct and keeping those things mapped up with complex data was tricky. How does Arduino handle that? So, if you have your Objective-C object or C struct and you pass it down through a Bluetooth, how do you decode what you are receiving? ANDREW: Arduino won’t give you any direct help with that but that’s how also not usually how I structure things. I normally would just create a pretty simple command set and instead of trying to serialize structs or objects and send those across, I’m just sending small bits of data. For example, with the garage door opener like we were talking about before – if you want to be able to control it from your phone, maybe you would just send a command that set open or just the string “Open” or a command that was called the string “Close”. Those were your two commands and it’s as simple as that. If you’re doing anything more sophisticated than that, you really have to come up with your own protocol and figure out how to parse that. That can get a little bit difficult but there are actually libraries out there to make some of that easier. I’ll try to put a link on the show notes but there’s one that I used and liked that I didn’t write called Packetizer. It just makes it easy to – instead of having to do your own low level parsing of incoming data and figuring out when you got a command, it handles that for you. You give it some simple information about the command you want to receive and then it deals with all of that buffering and looking for a valid command and calling you. It can make that sort of stuff much simpler. JAIM: Okay, cool. On the base level, it’s mainly string? You passed them back and forth or can you [crosstalk]. ANDREW: Yeah, well, or data. Think of it like NSData. It’s just data, just byte. There’s also a library which I have not personally used but I’ve seen called Firmata. This is an Arduino library that implements this protocol called Firmata and it gives you slightly more hand holding, I don’t know if that just sat right. It builds up a base for doing this kind of computer-to-device communication. It has a little bit of a message structure around it so you can, for example, send an analog value and then it deals with packaging that up and sending it to the computer and vice versa. There’s actually an Objective-C version of Firmata that somebody wrote so that you can put this in your Mac or iOS app and it will handle this low level stuff we’ve just been talking about and make it easier. JAIM: Very cool. What projects have you been working on? ANDREW: Well, I’ve got the Wired In signs that I’ve been working on. I’ve got a board called an Arduino Esplora which is – I actually picked it on an earlier show – but it’s an Arduino that looks like a game controller. The cool thing about is that it just has a bunch of built in sensors on the board. You don’t even need a shield. It’s got an RGBLED, a bunch of buttons, a joystick, a slider, a temperature sensor, a microphone, a light sensor. So that’s a fun board to get just to play with because you don’t need anything else and you can start doing some cool stuff. I’ve got one of those that I’ve programmed so that – it’s got an accelerometer on it – so its position in space is used to control the position of an object in Scene Kit. It’s actually in a Mac app. That’s been fun but Wired In is certainly the thing that I’m focused on right now. I do have an idea for making– I want to make an audio switch box for my stereo setup so that I can switch the thing that’s hooked up to my speakers through my iPhone. Then ideally, actually use IR so that I can control like CD player and that’s sort of thing from my iPhone. It better be cool. JAIM: The Wired In that you explained this a little bit last week, is it – is the Kickstarter still going? ANDREW: Yeah, the Kickstarter is still going. It’s wearewired.in. Since we recorded last week, we actually have hit our funding goal so we are excited about that. But we’re hoping to hit some stretch goals. I’m actually really excited about that. It’s the first time that I’ve had a Kickstarter project and it’s pretty exciting to have it fund and we’re actually going to make these things and get them out to people. ALONDO: Yeah, I’m actually pretty excited by getting them. I ordered – I think I [inaudible] where I get two, one is programmable – the customizable one and the default one. ANDREW: Cool. Yeah. Everybody I tell comes up with an idea for their – for what their sign to say and we’re having a lot of fun hearing from people. We actually had an article on Re/ code today and quoted Ina Fried saying she wanted one that said something like “Don’t bother me unless you have diet Coke.” [Chuckles] So we’re going to try to make one of those for her. JAIM: For those devices, that is, device that you put on your desk – it turns on or it turns off based on what’s happening – how is that wired up? ANDREW: Well, I should tell you that our hope is if we hit the stretch goal, you’ll actually be able to change the color of the RGB. iOS make the LED’s RGB LED so you’ll be able to change the color of the sign too. But assuming we don’t hit that stretch goal, you’re right that it’s just on-off. Well, you’ll actually be able to set the brightness, hopefully. It actually looks very similar to what I described with the garage door opener. I’ve prototyped this whole thing using Arduino. I’m starting now on the non-Arduino final design. But for the Arduino prototype, I just have a really simple protocol where you can send a message that is RGB and then a number from 0 to 255 for each of red, green and blue and that tells the sign which color to light up the lights. We don’t actually really need any communication from the sign back to the computer so the only thing I send is a little packet that just says, “I received that message successfully.” That way the computer can tell if it’s successfully – or the iOS device can tell if it’s successfully talking to the sign or if it’s lost its connection or whatever. It’s a very, very simple command set. JAIM: Okay, so this is controlled through your iPhone? ANDREW: Yeah, we actually have an SDK. It’s not public yet but we were planning to release it for iOS. It actually works on the Mac, too. And that’s pretty cool because Core Bluetooth is exactly the same on OSX and iOS so the code is literally identical. We just compile it for OSX, for the OSX SDK and for iOS for iOS. Yeah, Core Bluetooth is not – it’s a little bit verbose. You have to do a decent amount of boilerplate but it’s nothing crazy and it’s not scary. It’s really normal Objective-C code. We’re planning to open source that when project ships. I don’t want to open source it right now because it’s half-finished and the protocol is not completely final and all that. ALONDO: Is there a question about and it’s probably taken a bit of a setback outside of the iOS specific implementation and that is – say I get my hands on one or two of these Arduinos, am I be able to build something and take it back apart pretty easily to reuse it? Say I just want to learn because I’m really looking for suggestion for a great starter project for someone who’s new to microcontrollers. I’m looking for a project to do with youth that get them engaged in. It’d be great to hear “This is a great project.” You do can set it up and get back down and kids can really see how to program it, make it work and get it ready for the next class that comes in. ANDREW: Yeah, I definitely think Arduino is great for that. Because of what I described with the shields, those shields are just plug and they just plug in and stack. There’s no soldering. You can certainly just easily unplug them. One thing I think would be cool just off the top of my head is you can buy these little boards that are a matrix of LEDs. They’re a really low resolution screen and they’ve got ones that are available as an Arduino shield; are meant to hook up to Arduino and then you can really easily program them to just do a cool light pattern or to have a simple video game or whatever. But they’re simple enough that you can understand how the whole thing works. I think that would be a cool project for kids. There also things for doing music and there are midi shields and little synthesizer shields and there are shields so that you can make your Arduino play mp3s. Some of that stuff can be cool and capture kids’ imagination. ALONDO: Awesome. ANDREW: I think that the idea of putting it all together and then programming it with a group of kids and taking it apart for the next one is completely doable. I don’t think there’s anything hard about that at all. Speaking of shields, there’s a shield that I’ve been have my eye on that I want to try out. It’s a cellular shield. It allows your Arduino to hook up with cellular like 3G data connection. That sounds pretty fun. Imagine how hard that would be if you didn’t have the shield. You have to design your own cellular radio. I’m a hardware engineer and I would have no idea where to start. JAIM: Pretty complex. How would that connect? Would you need your cellular device registered with the company? ANDREW: Yeah, I think you have to. I think it takes a SIM card so you have to get a data-only SIM card and put it in there. You probably take the SIM card out of your phone and put it in but if you want to use it normally, I think you have to go buy a data-only SIM card from a carrier. JAIM: Okay. ANDREW: I don’t know. I don’t have one but I’ve been toying with the idea of buying one. I don’t really have a real project in mind for it. It just sounds cool. ALONDO: [inaudible] something that tell me when to water my garden or something like that if you have the necessary shields. I would like to receive that data that’ll come into my phone, maybe; or something like to get an alert “It’s time to water.” if it has been too long. ANDREW: Yeah, I think Arduino would be ideal for that kind of thing. There’s actually another device that’s not Arduino but it’s also really cool that I’ve played around with called an Electric Imp. The cool thing about Electric Imp is it’s the size of an SD card. It actually looks exactly like an SD card but it’s programmable and it’s connected to the internet through WIFI. They’ve also got a web service backend so if you want to – you can have the Electric Imp that’s hooked up however you want with sensors and whatever. It’ll look just like a REST API on the other side so you can write an app that will control your device using Electric Imp just using the same kind of REST API that you’re used to with that every iOS programmer has used. That’s something to look at too. My main problem with Electric Imp is they’re – if you want to put them in a real device, they’re not super cheap but they are really easy to get up and running with. The IDE for programming – those is like a web app. They even get programmed over the internet. ALONDO: Oh, cool. ANDREW: I haven’t really thought about it before but I’m sure you could use the Electric Imp with an Arduino. I’m looking right now. It looks like there are – I don’t know if you can actually buy a shield buy there are – yeah, SparkFun has an Electric Imp shield for the Arduino. It would be a cool easy way to give your Arduino this WIFI connection and the REST API to talk to. JAIM: Pretty cool. ALONDO: Awesome. ANDREW: I may have to buy one of those. JAIM: What are some patterns that you’ve recognized dealing with Arduino just writing code that you weren’t aware before that you found very useful? ANDREW: One of the big patterns is that, particularly for doing communication, if you haven’t done this low-level communication before, there are some tricks to it. I think the biggest mistake people make is they’ve designed a protocol that’s not very easy to verify when you get packets coming in. Designing your communications protocol is important. You should be able to tell when a packet starts and when it ends and if the whole thing is valid because if you lose data in the middle or something, you want to be able to detect that. That’s one big thing. Beyond that though – I don’t know – it almost feels like the programs that I’ve written are so simple. It’s hard to come up with a design pattern for them. I like to try to keep my Arduino code really cleanly structured and broken up into small functions just like I would do with an iOS app because it makes it easier to read. There’s certainly no reason you can’t do that. If a function is longer than maybe 15 or 20 lines at the most, I tend to think I could probably split this up and break it down. A lot of the same kinds of software engineering principles that go into writing an iOS app are equally valued with firmware. One different thing, of course, is if you’re running a program on an 8 MHz processor. You’re not going to be doing anything super CPU-intensive. You’re not going to be doing real-time image processing or something like that. That would be more where the Raspberry Pi would be right thing to use or just an iOS device. JAIM: If I do, you could do something where you pass the information. Like I always said, it’d be pretty hard to do over the network giving your passing on information that probably won’t work very well but it’s interesting to think about. ANDREW: Yeah, I mentioned earlier I don’t have direct experience with them but in the last little while, they’ve come out with Arduinos that are actually really quite powerful. Most Arduinos are really slow by iOS or Mac standards -- it’s slow processors. They’ve got some now that are actually more like Raspberry Pi class thing so you can do some real processing on those. JAIM: Very cool. Sounds like a cool product and a cool ecosystem. I’ve heard a lot about it but it’s good to hear a little bit more; get some more specific information.[crosstalk] ANDREW: I’m having a lot of fun. One thing I was going to mention to you is that all the Arduinos I’ve worked with – I think almost all of them –the way they’re programmed is over a serial port. That’s transparent to you because they just plug in with USB. That’s actually a really easy way to debug. We didn’t talk about debugging. Right now, for at least for most Arduino devices, there is no debugger on your Arduino. You don’t get just single set break points and single step through your code. I think you need to look into this a little more but I think that’s something that’s going to be added or may even already exist for some of the newest devices. But as it stands right now, most devices, if not all, cannot do that. You end up having to do printf caveman debugging. The way you typically do that is you want to have your Arduino hooked up to your Mac and then there’s a really simple library function that you can call to send data out on the Arduino serial port – just serial.print. Then, the Arduino IDE actually has serial terminal built-in so you can use that like a console. Debugging is not as easy as you’re used to if you’re coming from iOS or something. It’s definitely the printf style debugging and you have to have a thing hooked up to your Mac while you’re doing it. But that’s also makes a fairly easy way to communicate with your Mac. If you design a simple protocol, before you even have your iOS device hooked up or whatever, it gives you a really easy way to communicate to your Arduino by just typing commands into that window. JAIM: Very cool. Do we have anything else we want to cover before we get to the picks? ALONDO: I think it’s pretty well covered actually. JAIM: Yeah. We’ll open up the iPhreak rumor mill. We might be having a new panelist come on. He’s a big deal. Can’t announce the names but [chuckles] we’re pretty excited to have them on board. ANDREW: Whoever it is, I’m excited too. [Crosstalk][chuckles] JAIM: We’ll scare them. Hopefully you don’t scare them off. ANDREW: [Chuckles] Yeah. I would never do that. JAIM: Possibly next week, we would have some new guests to announce. ANDREW: I hope so. JAIM: We’re cool. Let’s get to the picks. Alondo, what do you have for us? ALONDO: Okay. Actually, I only have one pick this week. It is a work I just picked up and it’s called The 7-day Startup: You Don’t Learn Until You Launch by Dan Norris. In going to this whole startup venture on the side for a while now and it’s a nice to have some text that can work for, too and it keeps me motivated and gives me some ideas. I guess I could – I am using Amazon Prime to give this to you. I guess I could say the Amazon Prime is a pick. I just started using their [inaudible] because I’m actually borrowing the book versus a purchase. I’m still in a 30-day trial so I don’t know if I can say if it’s worth whatever price that they’re charging. But for now, it seems to be okay but it’s free. [Chuckles] So that’s my pick for this week. JAIM: Very cool. Andrew. ANDREW: I’ve got a couple of picks today. The first one is – I can’t actually say I 100% understand what this is but – it’s an article or possibly it was a talk from UIConf which I think just finished in -- I think it’s in Germany. I could be wrong [chuckles] about that. It’s written as if it were the Keynote from UIConf 1995. It’s called Object-Oriented Programming in Objective-C. It’s this article about how people who write their Objective-C with so much C baggage that they’re not actually getting the benefits of true object-oriented programming. He actually goes through an implementation of the Game of Life in Objective-C. It’s written using this style that will look a little bit formed to an Objective-C programmer where it’s really purely object-oriented and does away with all the procedural baggage from C. But that’s actually not the point of the article. The point of the article is that we are now with Swift where people who are in ’95 or whatever in Objective-C where it’s this new language but we’re all coming from a background where we’re so used to one paradigm that it’s really hard for us to learn a new paradigm without carrying along a lot of baggage. That’s his point. It’s that we need to not make that same mistake with Swift. That’s my first pick. JAIM: So I can write Objective-C in any language. ANDREW: Yeah? How? JAIM: I just do it. I’ll figure out [crosstalk] instant messages. ANDREW: Yeah. Even in Haskell or something. JAIM: I’ll find a way. ANDREW: Yeah. It was a good and fun article because it’s written as if OpenStep were the new thing -- this next operating system. My second pick is actually something that I’m unreasonably excited about. It’s a stereomicroscope made my AmScope that I just ordered today. I don’t have it yet but I am very excited to have because I have missed having a scope like this since I quit my last job where I got to work with one all the time. It’s for building hardware --electronics hardware -- with really small parts. It’s one of those tools where I know it’s going to enable me a bunch of new stuff. I was pleasantly surprised to find that it’s only $184 when previously the cheapest one I’d seen was $350. I thought that was cheap because the ones we had to work were a couple thousand dollars. It’s a nice cheap stereomicroscope for doing really small detailed work. Those are my picks. JAIM: Very cool. I think it’s a little early for the dub dub picks. Hold off on those films next week. I’ll be there; Alondo’s there. I going to have one pick. I bought a Telecaster-type guitar. I play the G&Ls which was started by the same person who did Fender but they make great guitars in the Fender styles. I’ve been playing a Telecaster for 7-8 years. The single-hole Telecasters that get a thin tone, that’s what everyone likes but I wanted a little deeper tone and I was looking for some pickups that can do it. I found one that I’m really excited about. I’m going to be ordering it pretty soon: the Charlie Christian Neck pickup. Charlie Christian was one of the early Jazz guitarist but they buy a lot of pickups and because of really cool sound to it. It has deeper lower sound. I do a lot of Jazz playing or something like that so deeper sound works. So if you’re looking for some different sounds out of your Telecaster, this is a really cool thing. I am looking forward to have this wired into my guitar. ANDREW: You should do it. You should do a special iPhreaks performance once you get it. ALONDO: Yes. JAIM: Before and after. I’ll be playing the Blues. ANDREW: I’m only half joking. I would love to hear that. JAIM: Here we go. You can fire it up. Get the amp in here. Crazy. New theme song. That’s it for our show. Thanks everyone for showing up. We learned a lot about Arduinos. Great. Andrew was our panelist/guest today. Thanks a lot. ALONDO: Awesome. Next time I’m on my way to RadioShack. ANDREW: Yeah. You really should. I buy my Arduino stuff there just because it’s around the corner even though I don’t know how much longer that would be true but still is right now. JAIM: Alondo’s actually in the car. ANDREW: [Chuckles] Yeah. [crosstalk] JAIM: Give me that Arduino. ALONDO: It’s basically 2005 years. I think it’s going to be hooking for a while. JAIM: Okay. That’s right. ANDREW: Yeah. JAIM: Perfect. It’s a time machine. ANDREW: Alright. Thanks guys![This episode is sponsored by MadGlory. You've been building software for a long time and sometimes it gets a little overwhelming. Work piles up, hiring sucks and it's hard to get projects out the door. Check out MadGlory. They're a small shop with experience shipping big products. They're smart, dedicated, will augment your team and work as hard as you do. Find them online at MadGlory.com or on Twitter @MadGlory.]**[Hosting and bandwidth provided by the Blue Box Group. Check them out at BlueBox.net.]**[Bandwidth for this segment is provided by CacheFly, the world’s fastest CDN. Deliver your content fast with CacheFly. Visit cachefly.com to learn more]**[Would you like to join a conversation with the iPhreaks and their guests? Want to support the show? We have a forum that allows you to join the conversation and support the show at the same time. You can sign up at iphreaksshow.com/forum]**

Sign up for the Newsletter

Join our newsletter and get updates in your inbox. We won’t spam you and we respect your privacy.