Getting conned into writing IoTuz/ESP32 drivers and example code

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so next up we have mark Mullen who was very busy last year with the project for the open hardware Minicon did a lot of software development for that so he's going to talk to us today about coding for SP 32 thanks mark thank you [Applause] so who was here last year and has one of these yes a couple few a few more over there yeah yeah I've seen yours crow so you might remember that yeah the hardware was already the software still had to be written and there was therefore a lot of things to do so that's what this small talk is about if you're interested in all the links and so forth I recommend you take a picture of this slide the link at the bottom gives you everything else including all the links that you'll see during the talk so that's an ESP 32 board you'll recognize the battery it's an older version of the chip and a bunch of I on it and I guess you'll get better pictures on the slides good kind of hard to show from here all right so you have all those lovely people some of whom you may recognize they all looked nice and smiley they gave you a little piece of hardware looks kind of sweet so okay I'll sign up how hard can it be right but anyway let's go back in history first they've done a lot of these the pebble v1 was many years ago I actually got one after the fact that's how I learned to program some do some Arduino code back the days and it was like oh that's cool I can do my own stuff I can make all these sensors work and then we had this mops and that board I was going to go into a rocket but I didn't have a rocket so I made a sleep monitor out of it that also was a lot of hours spent the pebble v2 was a new version of pebble v1 had nice little LCD so you could actually start writing that's why Stargate in trouble by writing my own or porting LCD driver for it and making use of all the LCD functions that were not available with the original code ESP plant was the first version of ESP chip that was I think two years ago now and then we had last year which was this low guy and kind of all it did was light up LEDs without actually giving you any control over them and showing a little pattern like that which was nice it sure that it booted but that was about it the rest was for you too right it was very nicely made board actually if you look in the back you can see all the i/o ports are actually listed so the only one issue with this board is as sweet as it is sadly I think it was only the run that was made for LCA I've had many people ask me how can i buy one and I don't think there's you can't buy one right yeah so or you can make your own because it's you know the hardware is obviously published and like every else here you saw the previous talks like oh we should do something oh it's next week oh it's tomorrow so the board was done and it worked actually quite well with a few details the software was kind of well there's a test code that shows that it works and the rest is for you to do ESP 32 was a new chip at the time so the libraries were also not really existent or not always working so really it was just kind of cutting edge and to make things easier they were actually two different ways of programming it one was the Arduino way with a layer that was not quite finished the other way was a low level where you could talk to the chip directly using a kind of a different way of programming which is more powerful but was just different for one I we I was used to so to make my life easier and we used some drivers that existed I just when the Arduino way means I only got to use one of the two cores but that was good enough for what I was doing so yeah showing the previous projects I got conned with some previous ones so this one I got cloned even more into writing code here's a few links from the previous projects so I'm not gonna go in details you can just get them if you're interested and because I didn't learn this does it last year I end up really writing I spending a lot of time writing code for this just because I had hardware and it didn't really do anything but it could do so much so one of the things the LCD sorry the screen that came with it was quite powerful the driver was not it was barely functional it was extremely slow and you had to use I think software spi cuz hardware SPI was even slower than software at the time so you could display stuff but this was not really good for anything else especially you know this scrolling or anything real-time so however by the end of LCA by not listening to enough talks and spending too much time on it I was able to at least make the touchscreen working and in a display it wasn't fast you had to ride very slowly to actually get those things aligned but you know it was a proof-of-concept then I was able to port the Adafruit code that did similar things that wasn't meant for this board work I got it working using their library and porting where was necessary that was using the accelerometer in the board so you could just take the board shake it and it would make those circles and then I was the NFL CA so I never being in a plane on the way to a ski resort where after the lifts close I had nothing much to do so they gave me a lot a lot of time to actually start writing code including pretty much low-level graphics library to go on top of the drivers and start writing your own menu system you could actually click on that it would like flash I'd show you what you selected nothing really you know fancy but it takes a while to write that way you could select which demo you want to run as opposed to reflashing it every time now I want to be used up that was already existing so a good programmer is a lazy programmer so I figured well there's gotta be some tetris code out there for Arduino and sure enough there was I wasn't actually meant to work on this but at least the underlying code existed and sadly it uses a different version of the TFT library that was not quite compatible so I had to kind of steal the primitives and pour them to the library that was existing for this chip but eventually success so I got Tetris working and I also got another version of breakout working too and they actually quite fast want I got proper drivers that were faster for talking to the screen as I mentioned it was really slow I also found some other code from yet a third version of that library because they were actually three different versions that were all incompatible that allow you to display bitmaps so this is a bitmap that's likely being scrolled by the rotary encoder you can see in the corner and then even found some demos I don't know who's old enough to remember the 8-bit computers we had back in the days people doing crazy things with them someone actually wrote some demos from those days and ported them to there was the teens ev3 I think and again same different libraries but I was able to take the underlying code and port it to that that screen and the code that their libraries that I did have so lots of nice little demos like these now one thing I was really annoying with this board is they had those two LEDs on them which looked very nice but making them work was actually kind of a pain in the rear because they were newer pixels and there was no working new pixel library for this chip so there was there was a library from Adafruit which didn't work because again it was a new chip so I was able to hack it enough to make it work but it was using interrupts and timing which don't quite work well on ESP chip because the ESP chip is always doing something in the background so anytime you have a delay and then you hope that things are gonna work all they works most of the time but not well enough and there was another person who actually started using the RMT functionality that's in the chip which is basically a DMA engine and lets you do IO separately from the CPU so you program it you say what you want and they will send the right eye waves to control those LEDs sadly when I used it the demo worked and as soon as I put into my code it would randomly stop working and I would change two nines of code and it would work and it would not work again and after week plus a work found out I was a code alignment issue and depending on how the code was aligned then the code would crash on out which ended up being a bug in the underlying libraries that got fixed since then so eventually I guess kind of hard to show for everyone but I was able to control the LEDs here I'm using a slider sorry it's kind of hard to present to everyone and really was a I was lucky at the time that there was one other person working on this and the person working on the Arduino emulation library Mila dev on github was super helpful in taking my bug reports problems and actually writing stuff on the fly when I reported problems or things I were missing so it took a bit over a month but thanks to him made a lot of progress rotary encoders those life turning buttons they're obviously not new technology but they're really a pain in the rear to actually use because they require very specific timing you can all the demo code you see is like a loop it says oh you're in that fast loop and you keep listening to it and if you do anything else and something happens in the middle you're missing a little blip and then the button goes in the wrong direction are you missing a click so the only real way to do it is to have hardware interrupts which of course were a new thing on the Arduino library for ESB 32 so that was also something that got added eventually I was able to I get code working - I mean it feels silly to spend so much time on getting a little button to know what it's going left or right but really it took a long time so finally that was to them while I was trying to show you have a slider now you can select on the screen do the level of each color and it actually called as one LED and the other one is actually the reverse color from it backlight so one thing I'm well does in the slides is even though the ESP chip has a lot of i/o all those IO pins were actually being used so there's an i/o expander that's designed to give you more i/o pins and in this case sadly the backlight control of the LCD is behind that IO expander one thing I want to do is make the backlight more or less bright and the way you do that is PWM just turning on and off very quickly but the i/o expander makes that you have to program the our expand and say please turn off then use another come into dialogues when you say please turn back on and that makes it a lot slower than actually talking to a pin directly on your chip so I'm able to do a little bit of dimming which of course I can't demo directly it gives me four levels of control light is flipping very quickly using interrupts and beyond that it just doesn't work so well because I don't have fast enough control due to the i/o expander hardware drivers so first I improved the Adafruit library to control new your pixels it's again not the best way to do it but there's so much code that uses the neopixel library that having support for it was helpful infrared was also missing oh I didn't bring my remote but I can use an infrared remote to control it they will change the colors turn off the screen whatever and again that's something that is interrupt-driven so having the interrupts for infrared if you don't run fast enough are the right timing it stops working and I was a little bit tricky on USB 32 because again it's why you and interrupts it's actually still doing things in the background but I was able to make it work well enough and pour that into the canonical library that most people are using so now I can actually read from the infrared port the Adafruit LCD library so minnow dev did a lot of work to actually make it go faster on the SPI for that ship which is a little bit different from a regular SPI on Arduino then I found some extra code of primitives that were missing in the Adafruit library and ported them so now you can have the basic head of food library and display bitmaps you can do scrolling virtual things that were not available before so grain coding interrupts were that was the rotary button I already talked about that the joystick another thing so the joystick was actually it's a very cheap piece of hardware it's not really centered so I had to write a higher-level library to detect left from right even though Center is not in the right place that's useful for the games then the i2c expander or a library where you just say hey I want to turn this bit on and off as opposed to going doing all the work low-level touchscreen input because you have several things sharing the same bus you have to select what device you want to talk to so talking to the LCD to actually say hey display something you cannot do that while you're talking to the touchscreen so you have to turn on the LCD say hey display this then you turn the that off you turn the touchscreen on and say hey is there anything touching you and you go back and forth the touchscreen itself being another cheap piece of hardware you kind of want to know what the person tastes touching and you want to map that with a screen originally I'd kind of hard-coded this and I realized well of course then all calibrated the same so I don't know if anyone hasn't remembered an old source or an old device like that at Palm Pilots you had to calibrate it by touching the pen and a few little dots on your screen and I would tell it hey it would say hey this is the center touch it and I'm gonna see where the center is on the touchscreen so that's how I did it and I wrote similar code for this in my case it was even worse because I actually broke the touchscreen while traveling it smashed it so it still worked but the touchscreen itself was completely broken so I brought on you I bought a new one from the internet which believe it or not actually arrived broken too so that was very nice I waited two weeks to get another broken one I gave two getting a third one that one actually worked and I realized that the input was reversed so when I touched one corner another corner it was opposite from the ones we got with the original device so the calibration code I wrote this actually detects if it's a reverse screen or not actually I'm a little bit ahead of the slides that's the other control so you're basically touching those little lines then it sees how far you go off the side of the screen it remembers the coordinates for each and it can see whether it's reversed or not which is doing in this case by its I did all of this now as I mentioned this board no one else no one has it except a few lucky people who were here last year it is actually a lot better than the reference board from that you get from the manufacturer at least for what I was trying to do but I was able to like hack it a little bit if you see the button at the top is of course the iota as the bottom is the reference port it does not have a touchscreen but I was able to add a rotary encoder and a joystick and then modified enough that oh and actually I have also an IRA reader here so I basically made a poor man's eye Oh tears out of that for people who don't have an i/o test so they can reuse my code and at least a benefit from some of the functionality the only thing mainly missing being a touchscreen and to make things simple it's not quite compatible with the ILA library so the expressive developer working on this made a library that works on both kinds of hardware and just detects and works all by itself so that's kind of helpful now one thing I've been doing since I started working on Arduino and going to LCA is I learned about Andy's ICO library on Arduino most code is going through a main loop it does something it goes down it goes down and then when the done it goes back to the top but if you're trying to do four things at the same time like reading the rotary encoder controlling the LCD brightness reading joystick reading the rotary sorry cynical encoder reading the humidity sensor the temperature and in displaying that if you're doing that synchronously it's just a pain especially because you don't want to be doing them at the same rate so that's why I call comes in I could if you say hey I want to run this code at this frequency which you can see at the this next screen so the LED handler runs every 10 seconds the rotary there's an interrupt that actually does the low-level work but then I can read that input and the handler and do something with it the infrared I only need to run it every times 10 times a second and so forth so what I caused actually meant to be running from an interrupt I originally did this but I realized if my code is running within interrupts I cannot do a lot of things because with an interruption allowed to do other interrupts or you know how to do Co control so you have it on the previous one yeah so in the end I'm just doing a poll and I'm running it instead of delay so I can run the loop quickly enough without actually bound being bound by the all the list of things you can do within an interrupt the newer pixels I mentioned that a little bit it's really a pain it was a pain in the rear so if you're interested there's links to make things even worse as if you're doing new pixels plus infrared there two things are very sensitive to timing and a lot of code you found on the Internet assumes that you're doing just that so that's running the Adafruit one for instance it just stops interrupts and then it does stuff and enters interrupts back on but if you're trying to read from the infrared port which itself needs to be running all the time when you're changing your LED you can't read from the infrared which is kind of annoying so I spent a fair amount of time trying to make both work at the same time and removing those issues on the SP 32 diem says you cannot be using the other fruit library because just turning off the interrupt is not acceptable if you're doing other things at the same time so there's actually a lot more hardware still on this board the SD card actually by the time I was working on this the driver for SD card didn't quite work now it does I just never got around to it the microphone and the audio does require special drivers that I did not find at the time it didn't really feel like writing because they were not obvious infrared there's actually are transmitting infrared LED wouldn't be too hard to use I just had no good use for it then I mentioned those two games I had those two games used yet another version of the TFT library I have a pretty horrible hack where I initialize it with the ally from Adafruit and then I switch over to that other library because it has so many custom code in it that it was just too much work to port it out that support it all so the game is actually talking to his own library why the end it's being done by a separate library so it works but once you run a game at the end you have to reboot because it doesn't work back with your original library but hey good enough for what I was trying to do and let's see yeah should you actually have one of those boards those are the links of the different things you can look at the code so you can actually run that code yourself steal from it and I have a little video showing a demo so the future yeah I'll be honest that it wasn't all for the fame and glory I think probably a couple of people used my code so I did at the end the day I was like oh okay that was kind of fun but you know I'm not gonna spend my whole life I already spent probably three months honors so yeah that's pretty but that's about as far as I got and I at that point I had like everyone else all the things that took my attention as I said yeah it wasn't for the flame grower glory or money but it sure was fun you have a picture of this link to these slides if you need all the links at the bottom and I can show you the quick demo which is just a video since I can't do see me use this link here I don't need the audio it's fine okay so that's showing the webs come on full screen so I'll show you how to initialize the screen then you get the menu system so like for instance the adafruit code a lot of those like that code wasn't meant to be interrupted by something else I'm using the buttons yeah that's a closed kind of shaking screen I'm using the buttons to get out of the demo that I'm in and that's done using background interrupts kind of hard to read them and you system even from here but one issue I had was the LEDs were very bright so I have a way to make him dimmer or just turn them off that's showing like a bitmap display using the rotary encoder there's actually a scroll function in the chip so you don't have to scroll yourself you just tell like to scroll yes and that was those were the very nice demos that I found which thankfully I did not have to write but I had to pour the underlying primitives that they were using and once I got that working all that nice demo code I got that for free and the guy who did that demo code we put a lot of work into it and I'm guessing you're gonna get a game probably yeah the bottom is actually showing the temperature and humidity sadly the analog recode on that ship doesn't work so well so like the temperature is wrong by quite a bit and changes all the time but hey well at least was a way to exercise the hardware and that's using yeah the rotary encoder on this one yeah I cannot suck at Tetris but anyway you get the idea especially when I'm filming with the other hand and that's about it I'll put back the slight if anyone cares about the link for screen yep I'll put back the same the last thing here display present this one okay that's the last thing yes question sorry not oh yes so right so basically you saying the SP 32 is a very key it has a lot of features the capable chip would I recommend using it I would say yes I when I got it was definitely green as in it was missing stuff the chip was there but the hard the software was missing and it was a bit frustrating when I hit all those things and realizing that I was like driving on a road I was being paved or crossing a bridge to where the other side of bridge wasn't finished yet sometimes had to stop the car so I wouldn't fall him to avoid definitely it got a lot better right in the last nine months since I stopped working on this do you think there were some bugs in that shape as I mentioned analog Reed was all over the map the new version of that shape actually has those bugs fix as far as I know a lot of people care about Bluetooth III which I didn't using this chip I understand that then the new version it's also working better so it really depends on what you're trying to do but all I can say is the amount of features you getting on that ship for the price is really hard to beat I mean compared to even a team Z that cost more or the regular Arduino chip I mean this really blows it out of the water and now if you don't care about all the art in the libraries and you're doing your own stuff and using the low-level programming for it then you get dual core and you get even more stuff so it's really up to what you're trying to do and how much effort you willing to put into it but if you you know if you're just trying to light up a few newer pixels you don't need this like you have a new pixel shirt I'm just using a regular all the chip because I didn't need this but for the price it's really hard to beat so you know just make sure it does what you need another the hardware support is try the drivers ops support is there and if you've you know if you have what you need there I I think it's a good choice yes outside of don't trust these guys and don't come to their home in ich hoffe most important thing I mean things I learned it was interesting to learn low level stuff when I had two poor drivers usually you know an Arduino you don't write your own drivers anymore you just take this library that lights up stuff and then you're done you just call it I had to go back to low-level C++ you know port libraries so it was kind of an interesting exercise and remind you two of the days where you had to do everything yourself even including like making a load of grid and then when you click on it it like flips the display to show you you actually clicked on it stuff like that it's not rocket science but it's the stuff you don't do anymore nowadays right because there's a library it okay that's everything so it was it's not like I would say I'm wiser from having done all of this it's more like hey this is all the stuff that I get for free and I never have to worry about and it was interesting to do at least once and then I think you appreciate the fact that you get all this for free nowadays and you don't have to write it like you used to 20 years ago and I think it was one more question there or are we out of time was it sorry no oh good all right thank you [Applause]
Info
Channel: LinuxConfAu 2018 - Sydney, Australia
Views: 225
Rating: 5 out of 5
Keywords: lca, lca2018, #linux.conf.au#linux#foss#opensource, MarcMERLIN
Id: tMJzZtL7bIE
Channel Id: undefined
Length: 28min 6sec (1686 seconds)
Published: Sat Feb 10 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.