Third try is the charm. Hello. How, are you. This. Is the participation. Part come on you're not the first I hear. Okay. My name is dr., Paula Norwich and I, will try. To persuade, you today that you can do with your Linux something, which you, might, not, have thought of by. Yourself, I hope. In. A sense in last year. And a half I noticed, that I am using. Microcontrollers. For less and less and that I'm using my Linux more, and more for more or less the same tasks, and the. Dead progress process, I actually, learned. Something which, I want to share, with you today. In. A sense my. Idea is to tell. You how to do something with your arm single board computer, in, this lecture we will talk, mostly. About all. Winner boards. But. If. You want a hint if you want to you buy, some, arm, computer. Please, buy. The board, which is supported, by arm the end, unban. Is, the project which actually maintains the distribution for our boards, and is, currently the best distribution. For, arms. Aside. From me raspbian, for Raspberry Pi but raspbian supports, only rho w pi but, if you have any other board please, take a look if there is an army import' if there isn't try, to contribute, one and if. You are just deciding which board to buy my. Suggestion, is by the one which is already supported. On. The other hand if you already did something similar you might have found some, references. On the internet about device, three and it, looked like magic. So we'll try to dispel, some of that magic today. Unfortunately. When. You start, playing with it one of the first things. You will want, to do is recompile. The kernel, on your, board so. Be, prepared to, compile. Additional, drivers, if they are not already included on, beyond, again, hearings, because, it comes with a lot of a lot, of drivers. Already included, and, this. Year, I will not say. Anything, which requires, soldering, which. Might be, good for you if you are afraid of the heat. But. It will be a little. Bit more than just connecting few wires not. Much more, for. A start let's start with the warning for, example you have a arms in, arms. Small, arm board and you want to have a real, clock, in it you know the one which keeps the time when the board is powered off has the battery and so on. If. You buy the cheapest, one from China which is basically, for Arduino, you will buy the device which is 5, volt device which, your arm, single, board computer, isn't you. Can modify the board, removing. Two resistors. If you want to but, don't tell anyone I to see, and will. Mostly talk about i2c.
Sensors Here, should. Be, 5. Volt tolerance so, if you by mistake just connected, and your data signals, are really 5 volt you won't burn. Your board but. If. You are supplying your sensor, with 5 volts please, double-check, that your that is sure to connect it to your board and nothing, bad will happen this, is the only warning I have for the whole lecture in. This example I showed you a. Really. Simple way in, which you can take the sensors ran I to see detect detected, its address. In this case it's. 68. We. And then run, load, 1 kernel, module and all of the sudden you're asleep I will have better baked clock just like your laptop does, but. How. Did. This journey, all started. For me about. Two. Years ago I was, very unsatisfied. With the, choice, of, pin. Outs which you can download from, the internet I, was, thinking something along the lines wouldn't. Be it, wouldn't, it be nice if I could print the pinout for any, board. I have with, perfect, 250. For 5. Millimeters. Spin. Spacing, which I can put, beside my, pins and never. Make. A mistake of, plugging, the wire in the wrong pin. And we all know that plugging the wire in the wrong pin is always the first problem, you have on. The other hand, you. Say oh this, is the great idea and you, are looking at your pin out which is from the top of the board and you are plugging the virus from the bottom of the board and all of the sudden your pin out has to be flipped but. Once you write a script which actually, displays, the pin out it's trivially, easy to, get to add options, to flip it horizontally or. Vertically, and. Create. Either, black, and white pin out if you are printing it a laser or, color, pin out if you are printing it on some. Kind of inkjet. So. Once. You have that SVG, which you can print and cut, with the scissors and so on it's just a script. On your machine so you could, also have the common line output, and then. It. Went all south, I started. Adding additional data, which you can see on this, slide in square brackets, with. The intention, of having. Additional data, for each pin for example, if I started. SPI, I want, to see that this pin is already, used so, I will not by mistake plug something into the SPI. Pins if I already have the SPI pin started, if I have the serial, port on different, boards, your. Serial, might be. UART. For on this particular. CPU but, it's the only serial, in your Linux system, so it will be Delta, device, 1, as. 0, for example so, I wanted to see all the data and in the process, I actually saw, a lot, of things which cannot know and I didn't, so today. Talking to you about it, of. Course in comment line because you might, rotate, your board well plug in the wires you can also do all the flips and things you you.
Already Saw in the. In. The graphic, part so. Let's. Start with the sensor okay, I said, cheap sensor, for eBay we'll get the cheap sensors from eBay but this sensor is for some, old PowerPC. Macintosh, it was attached to the, disk drive and the Macintosh used it to measure the, temperature of, the disk drive you know that was in the times before the. Smart headed temperature. And. I, said. Hmm this is the old sensor, can well surely. It doesn't have support for it but, oh look. You just grabbed through the kernel source and indeed, there is a driver and this, was a start I said hmm. Drive, it in Carlo I don't, have to use Arduino for it, so. Now. That, I know that driver, is there and they have colonel model compiled, we, said that prerequisite. Is that we can compile the kernel what. Do we actually have to program. Or do, to, make this sensor. Alive not. More than this a hole in the middle of the slide you, just echo, the name of the module and the i2c, address the i2c, addresses, we, saw it before we can get it we die to see detect by just connecting the sensor and the, new device will magically appear, it. Will be shown in the sensors. If you have alum sensors package installed, but. If you don't you can always find the same data in this, file system which is full, of wonders and as we'll see in. Non. Formatted, way so the first two digits actually. The last three digits digits. Are the decimal numbers and the all the other are, the. The. Integer, seals. Use in this case. But. You might say all but, I don't want to put the Tejo in my startup, script or I. Would like to have. That as soon, as possible I don't want to depend on the userland, to actually start my sensor and believe. It or not because, your smart, phones have various. Sensors, on there, is a solution of the Linux kernel for that and it's called the device tree so. This is probably the simplest. Form, of the device tree which still. Doesn't look scary, but it it will stay, with me and, it. Again defines our module, the, address. Which is 49 in this case and i2c, one interface. Just like we did in that a hoe but, in this case this module will be activated, as soon as Colonel starts, up as opposed, to at, the end of your boot up process. One, additional, thing that kernel, has and. Many. People, do not use, is ability to load those, device, trees, dynamically. The reason, why those most people don't use it is because they are on to old kernels, I think you have to have, something. Along the lines of four, eight or, newer. To. Actually have the ability to load the device trees, live. Basically, you are you. Are using this, kernel. Config. Directory. And this script just finds where you have it mounted and, loads. Your, device tree live, word. Of warning. Currently. Although it. Seems, like, you, can do that on Raspberry Pi the, API, is there, the model is compiled. Everything, is nice and Diddley kernel, even says that device, 3 overlay is applied it, doesn't work on the raspberry pi because.
Raspberry. Pi is different, but. If you gave a any other platform, live, loading, is actually quite nice and deadly. So. Now, we have some sensor, and it works or it. Doesn't, and we somewhat, suspect that, kernel. Developers, didn't write a good driver which. Is never. Ever the case if you, really want to implement. Some driver please. Look first at the kernel source tree there, probably, is the implementation, better, than the one you will write and you, can use because, the kernel is GPL, you can use that implementation, as a reference, because in. My. Small. Experience, with those drivers in Colonel they are really really nice but, what do you do well to debug it I said no soldering and I didn't. Say but it would be nice if I could do that without additional hardware. All, look, colonel has ability, to debug my i2c, devices, and it's, actually using tracing. The same thing I'm using on my servers, to get, performance, counters isn't. That nice I don't have to have a logic analyzer I can just start tracing and, have. Do all the dumps in curl oh nice. Unexpected. But nice. So. Let's get to the first cheap, board from China so. You bought your arm single, base computer single board computer, and you want to add few, analog, digital. Converters. To it because you are used to Arduino, and you have some analog, sensor, or something, and you, found the cheapest, one on eBay. And bought, few. Four. Five six, because. They are just the package, so. What do you do the, same thing we saw earlier, you just compile the models say. The address, of the interface, and it. Will appear, and. Just like it did in, the last example so. Everything, is nice but, but but you, read the datasheet of that sensor, and the, sensor other, than, for. Analog. Inputs, also. Has one analog. Output, which is the top pin on the left denoted. By a out. So. You. Want to use it, oh this. Kernel model doesn't is not very good it doesn't have ability, to control that of course it does but how do you find it my. Suggestion, is actually, to search, through, the C's for. Either address, of, your, eye to see sensor, which is this case is 48, or. For, the word output. Or input and you, will actually get all. Files. Because. In linux. Everything is a file which.
Are Defined in driver of this model, and if you look at it there is actually. Output, zero out. Zero output, file in which you can turn out put. On or off. So. We, are all golden, kernel. Developers, didn't forget to implement part of the driver, for this sensor all, golden. My. Original, idea was to, measure, current. Consumptions. Of arm boards, because. I'm annoyed by the random. Problems, you can have just because your power supply is not powerful, enough so it's nice actually to monitor. Your power usage so you will see what changes, for. Example you surely will. Get that remind, me to tell you how much power does the keep does, the additional. Button takes. That's. Actually interesting thing, which you wouldn't know if you don't measure current, so, you buy the cheapest, possible every, sensor for current the, right one is the iron. A 2 1 9 which is bi-directional. Current. Sensing, so you can put it between your battery. And I'd. Know solar panel, and you, will see whether the battery is charging, or discharging or. If you need more channels, I like, an a 3, 1 3 2, 2 1 which. Has bay which has 3 channels, the same voltage but 3 different channels so, you can power free, arm. Single. Computers, from one sensor if you want to. And. Of course once you have that again. The current is in some file and it. Will be. Something. But. But but I promised. You IOT, right nothing, I said so far is IOT where, is the Internet that is where the things you. Know the buzzwords missing, okay. Challenge. Accepted let's make button, you. Know it's like a blink. Late. So. 4 buttons, because I was not allowed to use soldering, iron, in this talk, I'm. Using old buttons, from old scanner, nothing, special 3, buttons, in this case with hardware, debounce but we don't care. Four, wires three, buttons, how, hard can it be, well. Basically it. Can be really. Really simple, this, is Bay this is the smallest, font so if you see. How to read this I. Congratulate. You in. This case I, am. Specifying that, I, want, software. Pull up in this first fragment, on the top which. Basically I, could. Have put, some, resistors. But you said no, no, soldering, so. Here I am sorry is telling, to my, processor. Please do me you pull up on those pins and then. I'm defining three. Keys as you can see email connect and print which, generates, real, Linux. Keyboard, events, so, if you are in Ex and press that key it will generate, that key I thought. It would it would be better to generate, you. Know the magic multimedia. Key bindings, as opposed to a B, and C because if I generated.
A DNC and was. Its console, I would actually generate letters. On a login prompt which I didn't want, so. Actually. Did it and it's. Quite, quite. Easy in. This case I'm using GPIO. Key keys, pulled, which. Means that my CPU. Is actually, pulling every. 100, milliseconds. Those. Keys to see whether they their, status, changed, and since, the board is actually connected, through the current sensing resistor, a current, sensing sensor I mentioned, earlier, I'm. Getting. Additional, how. Many milligrams. Every. 100, milliseconds, pulling, free keys. 60. I. Wouldn't. Expect my power consumption. To rise by 60, milliamps because, I am proving keys every 100, milliseconds, but, it did and because. I could add sensors totally, looks without. Programming. Drivers, I know, that. Why, am I using polling. Because. On all wiener. All. Pins, are, not interrupt, capable, so in the sense all pins, cannot, generate. Interrupts, on allwinner raspberry, pi in this case is different on raspberry, pi every pin can be interrupt, pin on Allwinner that is not the case so. The next logical question, is how do I know when, I'm sitting in front of my board whether the pin can get the interrupter, no my. My. Suggestion. Is ask the colonel just, grab through the debug, interface of, the colonel through, the pin CTL, which is basically the the, thing which configures, the pins on your arm, CPU. And. Try. To, find the IURC, you, and, you. Will surely, get the list of the pins which are, which. Are irq capable, take, in mind that, this, will be different on different arm, architectures. So unfortunately, on allwinner, it will always look the same because it, solve inner architecture, actually. Suksoon, see. But. On the Raspberry Pi for, example, this will be somewhat different but, the colonel knows and the grep is your friend, so. You wrote the device three you load it either live or some. Something, on, some, other way you connect, your buttons, and now let's try the, stree work of course, it does we, will start, evil, test which. Will show us all the input devices we have the new one is the GPIO, free buttons which is the same name as our device three over and, we. Can see that we see the same things we saw in, device. Three we defined, three keys with this event but. We free-of-charge got, for, example keyboard repeat because. This, is actually meant to be used for keyboards, our kernel. Is automatically. Implementing. Repeat key we can turn it off but this is example, of one of the features which you probably wouldn't, implement. Yourself if you are connecting, those three keys to, your. Arduino. But. But but this is still not the internet-of-things. If this, is the Internet it should have some kind of, Internet in it some buzzwords, for example mqtt, and. It. Really can just install, trigger-happy. Demon, which, is nice, diamond which basically, listens to input events and write, a free file configuration. Which will send the each, key pressed order MQTT, and. Job. Done i did. The internet button without. A line of code the, configuration. One. Side note here if, you are designing some, some. Internet. Of Things thingy. Which. Even. If you are only one who will use it it's, a good idea but, if you are doing it for somebody else please. Don't. Depend, on the cloud, because. I wouldn't like for my door to, be locked, permanently. With me outside just because my internet connection, isn't working, think, about it. Of. Course, you can use any buttons, in, this case this, was the first, try, actually. Like the three buttons better than this one that's why this these. Buttons, are coming second and this. Board with the buttons has one additional nice. Thing and that is the LED. We. Said that will cover buttons, and LEDs right. Unfortunately. This LED, is 5, volts, so it won't light up on 3.3, volts but. When. You mentioned. LEDs, something. Came to mind how. Can I use. Those LEDs, for something more, useful than just blinking, them on or off we'll, see you later then turning. Them on or off it is also useful, you. Probably didn't know that you can use Linux. Triggers, to, actually, display. Status, of your MMC. Card CPU. Load network. Traffic or something else on the, LEDs, itself, either, the, LEDs, which you already have on the board but if your manufacturer. Didn't provide enough of them you can always just add random LEDs, right device 3 and Jenny and define. The trigger for them and this. Is an example of that. And. This. Example is actually for this board which, is from the ThinkPad. ThinkPad. Dock to be exact which. Fortunately, which, isn't at all visible on this picture but you will believe me has actually two LEDs, and. These. Free keys and toy LEDs, actually. Made. The arm board, which doesn't, have any buttons on it or status. LEDs. Somewhat. Flashy. With. Buttons, that's, always useful on, the, other hand here. I would, just want to share a few hints, with you for, a start first, numerate. Your pins because. If you compared the the, picture down there which, has seven. Wires and are. Numerated. Which is the second try be, the first.
Nodes, On, the up you. Will see that in, this case i thought that there was eight wires so. The. Juice, what. Is connected, where when you have the wrong number of wires is maybe not the good first step, on. The, other hand we. Saw the keys what. About rotary encoders, for years. I, was trying to somehow. Persuade. Raspberry. Pi 1 as the, lowest. Common denominator, of all arm boards you know cheap slow, and, so. On to, actually work with this exact, rotary, encoder the cheapest one from the Aliexpress. Of course. See. The pattern. I tried. Python. I try the teaching, interrupt into Python, I tried Z, code and, nothing. Worked at. Least didn't work worked, reliably, and. If. You just write the small. Device tree say. The correct, number, of steps you have at your rotary, encoder because by default it's 24, but this particular robot, is 20 you. Will get, perfect. Input. Device for your Linux with just a few wires. Amazing. So. We, saw the buttons, we saw the LEDs we have everything for IOT except, the relay so. You, saw on one of the previous pictures this relay, box it's basically. Four relays. Separated. By optocouplers, which is nice and my. Suggestion. Since. You. Can't, in, device, three you can't say, this. Pin will be output, but. I want to initially, drive it high or I, want to initially drive it low it, seems, like. You can say that it's. Documented, in documentation, it's, just not implemented. There on every arm architecture, so you can write it in device three but your device 3 will ignore, you but. You. Can and this, might be somewhat. Important, because for. Example this relay is actually powering all your other boards, and you don't want to reboot them just because you reboot the machine. Which is actually driving the relay so you want to control that pin, as soon as possible. So. My suggestion. Is actually to. Explain. To Linux kernel, that this relays, is actually, 4 LEDs, which, is somewhat. True because the river has the LEDs, on it and then. Use LEDs, which, do, have the default state which works to actually drive it as soon as possible, as the, kernel boot because, kernel, will boot it will change the state of those pins from input to output and, set them immediately. To correct value so you hopefully. Want. Want. Power cycle, your other ports and then you can use the LEDs as you would normally use them in any other way. If. LEDs are interesting, to you have, in mind that on your on, each, of your computers, you have at least two LEDs but this caps lock and one is non lock on your keyboard and you, can use those same triggers, I mentioned, earlier on your existing, Linux, machine using those triggers so, for example your caps lock LED can blink as your. Network traffic. Does, something, on your network. Really. It's, fun. On. The other hand if you have a Raspberry Pi and, you defined everything correctly, you. Might. Heat into, some kind of problems, that, particular, chip has default. Pull ups which you can't, turn on for, some pins which are actually.
Designed. To be clocks, of this kind or another so, even if you are not using that pin as the SPI clock whatever, you do in your device 3 you won't be able to turn off actually. You will you will turn off the, the. Setting, in the chip to for the pull up but the pull up will be still there actually. Thought that there is a hardware, resistor, on board but there isn't it's inside, the chip, just. Word. Of warning, so. If anything I would like to, push. You towards, using, Linux kernel, for the sensors, which you might, not think of as the first choice if you just want to add some kind of simple sensor to to. Your Linux instead. Of Arduino, over serial, port which I did and this, is the solution which might with much less moving parts or wiring. Pie and. In. The end once, you make your own shield, for us but if I you will have to write that device 3 into the EEPROM, anyway so it's good to start. Learning now, so. I hope that this was at, least useful very interesting, and if, you have any additional questions. I. Will be glad, to, to. Answer. Them and if, you want to see one of those, all. Winner board which can be used with my software, to show the pin out here is one board which cost actually board me yesterday and in. Which yesterday. Evening, I actually ported. The. My. Software, which is basically just writing the definition of those pins over here and the pins on the header which I basically copy pasted, from the excel sheet just. To show that you can actually do that for any board you have with. Just, really. Pin out in textual file it, that symbol. Here. Are some additional links and do you have any questions.
2018-05-03