 in remotion with hardware. My name is Mark Villacampa. I'm called the same anywhere on the internet, so if you find a Mark Villacampa that is not me, just tell me. So yes, a little disclaimer, I'm Spanish, so I'm from Madrid. This is my first talk ever in English, so I hope everybody understands me, and if I'm not making sense or I get stuck, just throw me something and I will repeat, okay? So I work for a company called Cavify in Madrid. We have a service similar to Uber, where you can ask for a car, for a hiding car and a chauffeur from your phone. We provide service in Spain, in Mexico, in Peru and in Chile, so if you ever go there, you can try us, and we are expanding quickly, so probably in more places soon. We've been using remotion since mid-2012. Our main iOS application has been written in remotions since then. I think we were one of the first companies to switch from an Objective-C to remotion. We've been really happy. So this was 2012, starting of 2012, and I was starting learning Ruby, and I started like everyone else almost with Rails, but then I found this other project called MacRuby, which back then was not, was little known, so you could write OSTAN applications with it, and I started tinkering with it. I started going on IRC and actually bothering Watson and Joshua and asking these people questions because I didn't even know Ruby back then. So little bit after that, remotion came out and the first time, like the first time, the first day it came out, I just bought it right away because I was waiting for that for a long time because I wanted to write applications for my iPhone and I couldn't with MacRuby. And at the same time, I was going to give a talk at the local MacRuby group, and I was going to talk about MacRuby, and then just like after a month, less than a month after MacRuby, actually the remotion came out, I said, okay, maybe I can add remotion to the talk. Back then I didn't, I could barely write any Ruby, so I thought it was crazy to give a talk about that and just a month after the remotion came out, so I thought, Jack was saying this in the first talk this morning, I think. I knew very little back then, but yes, the little I knew, I wanted to teach everyone else because that's what forces me to learn even more and even if all those people knew more Ruby than me, probably I knew just a little bit more about MacRuby or remotion than back then, so I think that's important but even if someone else knows a lot more than you about something, you probably know a little bit more than them out all the things, so you can probably exchange knowledge, right? Yeah, so I also, like one and a half years ago, I co-founded a company with some college friends and we created Assembled and Sol, personal 3D printers, they're in Spain, so with a 3D printer, you can do many things. You can create anything that you can design in a CAD program and one of the things we did was we built these little robots, so I actually have it here. Okay, so this is a 3D printer robot, all the white parts that you can see there are actually designed and 3D printed and this is also open source, so all the files to print this robot are actually up there on the internet that you can download it and if you have a 3D printer at home, you can print it and you see this little board on top, this is an Arduino board, like an Arduino Uno, so it's a really common piece of electronics, right? And I thought maybe I can connect these two things together, these two things I like, remotion and these little robots, I would like to use both together, right? So I started investigating different ways that I could do this and being pragmatic as I tried to be, I said, okay, let's go for the minimum thing that you can find, which is like the basic technology behind something, so this little chart that probably analysts like this for quadrants chart, there are probably more characteristics that you can ask for in, or you can look for in different technologies, but for me, the important ones was what the range of the connection, like how long can you connect to this thing? So, and also how easy it is to get set up because I didn't know much about software back then, I don't know now either, but so yeah, for long range, of course you want something that doesn't use a cable, so you have Bluetooth and Wi-Fi. In an iPhone, there are only these two things that you can use to connect wirelessly to something. And I was looking at the ports on my iPhone and I did only see two, which is the jack connector for the headset and the lighting connector. And after doing some research, I thought that Bluetooth was way easier than Wi-Fi to set up and lighting connector was easier, maybe not to set up as a developer, but for the users, for someone else to use, right? So I'm going to give a little overview of the different technologies, some actual projects that you can use to use these other technologies and maybe some commercial use cases for those. So the first one is this project, which is by the University of Michigan. This little thing connects to the jack in your iPhone and it actually uses a low-level protocol using the microphone and the audio system. So you can transmit messages, you can modulate and the modulate messages between this word and your iPhone. This is actually what a startup called Square uses for their CAD reader. So they basically have this square device, they plug it in your jack and they have this app and you can just swipe your credit card and it modulates the data in the magnetic band so that the CAD can read it, right? But the problem with this approach is that the hardware is more complicated. It's really a custom hardware that you have to build, so it's not easy to get set up and also the jack doesn't give you enough power to really do something useful. So unless you're a startup like Square with a lot of money, those guys actually had a custom chip built so you didn't need an external battery for the device. So this is more complicated. Another thing you can do is you can go talk to this team guy and ask him for an MFI license. MFI stands for, I think it stands for Made for iPhone and Made for iOS. And this is a program that Apple has for third-party companies to create accessories, official accessories for the iPhone. But the problem with this is that there are a couple of disadvantages for companies. There's the information, like most things with Apple, the information is not public, so you have to actually go talk to Apple. So like any other service where you have to go ask for the price is probably expensive. And also there is this program where you have to share some revenue with Apple and they have these very strict quality control, licensing things and all that. And also for some, depending on what you want to do, you have to include a proprietary chip from Apple to do the authentication with the iPhone. So yeah, that's a bit complicated. But in case you are a bit crazy and want to go this way or you have a lot of money, you want to create a device and sell to millions of people, the actual framework that you have to use to talk to these devices is public. It's called external accessory kit and it just has three classes. I haven't really read the documentation of this because I haven't used it, but probably it's not very difficult. There is also this company called Red Park. They built this lighting serial cable. This is an actual MFI device, so these guys actually have a contract with Apple. They made this official cable and what you can do with this is they have this SDK that you can include in your application and you can connect this cable. This is actually a serial cable. So this cable probably has a lot of use cases in industrial setups, like in factories, they don't use wifi or Bluetooth because that's more unreliable. So if you want to actually connect to a mainframe or whatever you have and you want your employees to, for example, do it from an iPad, from a tablet or whatever, this is what you could use. But the problem with this is the MFI devices. So the MFI devices are attached to only one application. So you cannot go buy this cable, build an app for it and just upload it to the App Store until you use it to buy this cable. You actually, every device is attached to a boundary identifier or something like that, right? So you have to license the technology from this company and actually build your own cable, even though it's the same hardware. So yeah, if you're into that, that might be another solution. So that was physical hardware, physical connections. Now we're switching to wireless. So this is, now we're switching to wifi actually. So one door is this technology which many of you have probably heard about. It has many names. Whenever I have to Google something about it, I go crazy because everybody calls it different name. So this is actually a networking protocol for automatic discovery of wifi or ethernet devices connected to your same local network. This is for example what AirPlay uses under the hood. And it's useful if you want to set up, easily connect to a device on your same local network. It's pretty cool. It's actually probably what OS then uses to connect to other computers on the same network or to connect to an Apple TV or whatever. And there's just these two classes that you have to learn about to actually advertise a service from your computer or from your device or to actually browse the local network to find all your devices. Is it NSNet service and NSNet service browser? Yeah, Apple has a few examples with this. So in case you want to actually use when you're with your hardware, I for example bought this small device which is called the Spark Core. This guy's actually did a Kickstarter a few times ago. So what this actually uses, all the hardware actually just comes down to chips. This is silicon. So most of the advantages in these areas come from a big chip company releasing a new cheaper chip that you can put in your hardware. So for example, there is the, well, the name is wrong. It's Texas Instruments, but the actual chip is CC3300. This is a device, a really cheap device that enables your hardware to connect, to have Wi-Fi. So this is just a little word that this guy's from Spark made. And yeah, it actually has a small ARM processor inside that you can program and you can do all kinds of stuff with it, it actually has this output, these pinouts that you can connect to other hardware. So yeah, this could be a, they have a really nice documentation. They have this online IDE that you can even program this device from the internet. So I like these kinds of companies that actually take this more complex technology like this Texas Instruments device and they build an actual board with good documentation so that normal people like us can use it. I think this is good. Then there is, finally, there is Bluetooth. I'm more specifically the latest version of Bluetooth which is Bluetooth Low Energy or Bluetooth 4.0 which is basically the same thing. And Bluetooth has this really, really nice framework or core Bluetooth. But like any Cocoa API, it's a bit complex to get all the concepts. So I'm going to do a no bullshit explanations or explanation of the core data classes. So there are only a few. CV Central Manager is just the class you use to discover and connect to Bluetooth devices nearby. CV Peripheral is actually the class that represents a device that you are connected to or that you just discovered. CV Peripheral Manager is the class that helps you turn your iPhone into an actual Bluetooth elite device so you can actually create, turn your iPhone into a Bluetooth elite device so other devices can connect to it or even other iPhones. CV Central is the other device that connects to yours when you have actually turned your iPhone into a Bluetooth elite device. And so if you've ever used any Bluetooth device in the past, for example, Bluetooth 2.1 which was the most used version of Bluetooth before the Thelike amount, you actually have to go, if you use it from the iPhone, you actually have to go to the setting and you have to go to this menu and you find all the devices and you pair with those devices in there. But Bluetooth 4.0 is completely different. It's not the same concept. So you don't have to actually pair with that. You pair from your app, right? And every Bluetooth elite device doesn't have just one purpose or one profile as they call it in Bluetooth 2.1. You actually can advertise different services. So a service is just an abstract thing that an abstract feature that your device has. And each service can have even some sub-services and it can have also some characteristics. And a characteristic is something that you can, it's a value that you can read from that device or that you can also set. For example, if you have, I don't know, a head rate monitor, which is like the always the example for Bluetooth devices, you can actually read the value of the head rate or you can set some setting to, I don't know, change the color of a lead or whatever. And also there's these things that you have probably heard about because they are very popular lately, which are the iBeacons. And again, I'm going to demystify iBeacons. iBeacons are just Bluetooth elite devices for which Apple has made this cool DSL where you actually know the location of the iBeacons in the room. But actually they're doing nothing more than reading the strength of the signal that you're getting from that device so you know how close to the device they are. So you could actually even implement your own iBeacons DSL on top of core Bluetooth, okay? And also, you might know this one technology that I haven't talked about. I'm not the only one, Apple has been ignoring this at the moment too, which is NFC, Near Field Communication or whatever it's called. This is this thing that people say it's going to be the next thing for payments because you can just put your phone on top of the eraser and you can pay with that. But actually iBeacons can actually be used like if it was an NFC device because actually Apple is already using this. I don't know if someone here has an Apple TV but to set up an Apple TV you actually get your iPhone and you put your iPhone really close to the Apple TV and it gets your Wi-Fi information from the iPhone and also a couple of more pieces of information. So actually iBeacons can be used as if it was NFC. So if anyone is in the room and is going to write an article that Apple is going to add NFC to the iPhone, I don't think so. Okay, so there's another cool thing that you can do with Bluetooth low energy that very few people know about and it's been around for like more than a year. It's called the Apple Notification Center Service and this thing allows you to read all the notifications from the Notification Center on an iPhone from a Bluetooth elite device. So if any of you have heard about the Pebble smartwatch, this is just, I think probably the most famous smartwatch up there, they did this Kickstarter. I think it was the biggest Kickstarter ever. And what they do is they pair with your iPhone and you can see all the notifications in the actual device. And this is a service that Apple provides. What they do is actually they turn your iPhone into a Bluetooth elite device and they advertise this service which is actually the Apple Notification Center Service and you can actually read values from this Bluetooth elite device that is your phone and these values are just the information in your Notification Center. So you can see how you can build these really cool things on top of Bluetooth elite and this service and characteristics and all these things. It allows you to create these really good abstractions on top of this technology to build cool things. And yeah, I think you probably by now you know that the technology that I like the most is Bluetooth because it's the one I've been talking most. And I don't know if you know the next week there's this conference that this fruit company is having and I think they're going to announce some cool things regarding this whole Bluetooth thing. I don't know if it's going to be a revamp of the Notification Center or something else that I would keep an eye on it if you like this thing. So actually I haven't talked about any third party devices that you can use for Bluetooth elite. You can probably buy some iBeacons somewhere. I think there's this company called Estimote in New York that built some but I actually want to go to something more with which I can do more things. It's more versatile and I can program it the way it went. And I found this small device called the HM10. This actually uses the another Texas instrument processor. It's called the CC2541, whatever. It is the same family of chips that they payable. For example, the smartwatch that I was talking about uses. So this board is actually a Bluetooth elite to serial converter. So the serial, this protocol has a couple of names that you are, RS232, it's basically a serial connection. And this is the easiest way that you can connect to any hardware. For example, to an Arduino you connect using a serial, a USB to serial converter. So it's probably the easiest way and almost any hardware, any Hopi hardware that you're going to use, you're going to be able to talk to it through serial. So I bought this board. I actually bought this board. It's actually, it has to be soldered to another breakout board where you can actually have these pins where you can connect the stuff. So you actually have one here. So it's this little thing, that's these pins over here that you can connect to. Yeah, so this is actually made by a Chinese company that I cannot pronounce. So I am not going to. But you can actually buy it, it's really cheap. I think it was like $10 for the thing. And you can actually, using another serial, USB to serial converter, which I encourage you to buy one because it's really useful for any hardware job that you want to do, it's going to be useful. So you can send these commands through serial. So serial protocol is just a way to send and receive strings from other devices. So you can send all these commands. So you can actually configure this thing to advertise different services, different characteristics. You can even make it work as an IB con. But the main service that this actually advertises is a serial service with a serial characteristic. So you can actually connect to anything. I'm right here, it's connected to an Arduino board, but you actually can connect to anything that has a serial port. And if we are going to connect it to an Arduino board, if you had an Arduino DUE, which is one of the latest versions that has an ARM device and ARM processor, you can actually run Ruby on it. So you could run Ruby on your iPhone and connect to an Arduino running Ruby. Because there is this M-Ruby project. I don't know if many of you have heard about it. M-Ruby is just a small implementation of Ruby that runs on, it's target to run on embedded software and on embedded hardware. It was started by Matt, by the creator of Ruby. I think it is, I don't know if it is already invested in 1.0, but I think it's getting there. It's been around for a while. One thing that amazes me is that I think it is, it is actually founded by the Japanese government. Just crazy for me because the Spanish government would never do something like that. But yeah, it's crazy. So you can check, that is actually not the M-Ruby repository, the M-Ruby repository is probably M-Ruby slash M-Ruby, but that one you can easily, that's like a gem for M-Ruby that you can easily use to connect to an Arduino. So you can check it out. And some places you can go by stuff because I think for a software person that wants to get into hardware, the most difficult thing is actually finding the actual hardware that is going to be useful for you. Like you get into eBay and you get all these different devices that you don't know about, the documentation, there's no documentation, I don't know. It's really difficult to find those. So I've given a few examples for some devices that you can buy that are going to work. And yeah, there are a couple of companies here in the USA that this Adafruit and Sparkman, these guys actually, these guys do the, like they're mostly open source, they have mostly open source hardware, they actually build their boards. So, and they have really nice documentation. So that's the good thing, right? Because otherwise you have to Google the documentation, find it somewhere else and it's more difficult. And also there is this other company in China called SeeTheStudio, they have all this open hardware also that you can buy and they ship worldwide. So these are mostly the websites that I buy from and then of course eBay and all these other places you're going to find a lot of things. And I also like Geekestarter a lot because I think the Geekestarter companies is one of the responsibles for all this hype that's going around hardware lately because it's so easy to just design something, put together a prototype, put it on Geekestarter, get some money and actually build it because otherwise it's really difficult to get all the money necessary to manufacture all these devices in a quantity that you're going to get a reasonable price for. So I think every week a couple of Arduino related or hardware or projects are going to be around. I think Mark has something on hand also. So I encourage you to Geekestarter, see what projects are going on right now and maybe back some of them because they're usually really cool and also open source. And I would like to announce a project that I've been thinking about for a while which is motion Bluetooth. So what I want to do is create a DSO on top of core Bluetooth that has some more Ruby way of doing things and which helps you get easily connected to any Bluetooth heavy device. So it has this, I'm going to show you some code. It has this similar to Active Record device where you can actually describe the devices that you want to connect to and you can just go find them and get these callbacks. So it's callback based instead of delegate based because I really like the eventable model in bubble wrap. I don't know if anyone uses it. I use it all the time. Yeah, so it's very, like I just hacked together something for the demo. The actual code is really ugly but I think I'm going to get working on it and I would also like to announce support for Android and also Blackberry and MS-DOS phone. I'm going to get working on it whenever I buy an Android device because I don't have one. Yeah, so let's do something. Oh, this guy's not moving. It should move. So you guess that after all the research that I did, I finally managed to make this guy move from my phone, right? I hope so, let's see now, right? So, yeah, I think, yeah, just one more. Yeah, so I think Johnny Ive will be proud of me. You can see I'm not a designer. So this is what I hacked together. I think it's self-explanatory, right? You have this label on top which tells you if you have connected to the actual robot and you have these buttons without borders that you can tap to do things with the robot, right? So, yeah, and it's accessible also because Houston was playing with it before. So, yeah, let me show you some code. Yeah, so the API is just something I hacked together so nothing is final and I'm just actually still thinking about possible use cases because I haven't used Bluetooth enough to know where all the use cases. So probably the API is going to change but it should probably look something like this, right? So you have this base class that you inherit from if you want to declare a new Bluetooth LE device. So, you know, in Bluetooth 2.1 when you go to the settings menu and all that you have all these names for Bluetooth devices. In Bluetooth LE you have that too but like every device has a name. In this case, I'm going to tell my app that there's going to be a device called Puppy that you want to connect to and you're going to describe a series of services and characteristics that the device is going to have so that you can find devices with different methods. Like you can tell, okay, go find any device that I have declared and if it finds a device that you have declared it's going to connect to all these things or maybe you can tell it to just connect to, go find and connect to a device of this particular class or that has this particular service advertised or whatever. Okay, so I have the app here and it's just connected because well, I couldn't show you the code but what it's actually doing is so I just define that class in there and then I actually define some callbacks on the actual robot class using an API similar to the eventable module in bubble wrap which is just like passing some callbacks to it. So I have a callback for when the actual device connects and that callback sets the label here it actually sets the label on top and then I have some callbacks for when it disconnects when it discovers the services on the device and when it discovers the characteristics inside those services. So actually inside the characteristic what I'm doing is just when I find the characteristic that is, which is just an UID that describes the characteristic that is the serial module I'm just saving it, I'm detecting it and then I'm enabling the buttons and what it's button does is just it's writing a value inside, it's writing a value to that characteristic. So this is like a self made really small protocol that I made the actual code in the Arduino on the robot is a really small switch where I tell it if you get this from the serial you're going to do this. If you get this other string you're going to do this. So I have this small protocol where if I send an S the actual robot is going to stop. If I send a U it's going to go forward. You get the idea, right? So going forward now I think I'm going to turn right and then go forward again. This floor is not really good for the robot. I think it doesn't like this floor anyway. Yeah, yeah, yeah, so that's it.