Posts | Comments

Planet Arduino

Archive for the ‘engineering’ Category

In case you missed it, the big news is that a minimal Arduino core is up and working on the ESP32. There’s still lots left to do, but the core functionality — GPIO, UART, SPI, I2C, and WiFi — are all up and ready to be tested out. Installing the library is as easy as checking out the code from GitHub into your Arduino install, so that’s exactly what I did.

I then spent a couple days playing around with it. It’s a work in progress, but it’s getting to the point of being useful, and the codebase itself contains some hidden gems. Come on along and take a sneak peek.

The Core

arduino_logo_pantoneAn Arduino isn’t worth very much unless it can talk to the outside world, and making the familiar Arduino commands work with the ESP32’s peripheral hardware is the job of the core firmware. As of this writing, GPIO, WiFi, SPI and I2C were ready to test out. GPIO means basically digitalWrite() and digitalRead() and there’s not much to say — they work. WiFi is very similar to the ESP8266 version, and aside from getting the ESP32 onto our home WiFi network, I didn’t push it hard yet. When other libraries come online that use WiFi, I’ll give it a second look.

SPI

The SPI routines in the ESP32 Arduino port both work just fine. I tested it out by connecting a 25LC256 SPI EEPROM to the chip. The ESP’s extremely flexible hardware peripheral routing matrix allows it to assign the SPI functions to any pins, but the Arduino implementation is preset to a default pinout, so you just need to look it up, and hook up MOSI to MOSI and so on. As of now, it only uses one of the ESP32’s two free SPI units.

With SPI, some of the weirdness of using Arduino on a powerful chip like the ESP32 start to poke through. To set the speed of the SPI peripheral, you can use the familiar SPI_CLOCK_DIV_XX macros, only they’re scaled up to match the ESP32’s faster CPU clock speed. The end result is that SPI_CLOCK_DIV_16 gives you a 1 MHz SPI bus on either the 16 MHz Uno or the 240 MHz ESP32, which is probably what you want for compatibility with old code. But 240 divided by 16 is not 1. In retrospect, the macros would be better defined in terms of the desired frequency rather than the division factor, but you can’t go back in time.

There were also two extra definitions that I had to add to the program to make it run, but they’ve both been streamlined into the mainline in the last eighteen hours. That’s the deal with quickly evolving, openly developed software. One day you write that the macro MSBFIRST isn’t defined, and before you can go to press, it’s defined right there in Arduino.h. Great stuff!

I2C: The Wire

esp32_pinmapThe I2C (“Wire”) library has also gotten the ESP32 treatment, and worked just as it should with an LM75 temperature sensor. This is my standard I2C test device, because it lets you read a few registers by default, but you can also send the sensor a few configuration options and read them back out. It’s not a particularly demanding device, but when it works you know the basics are working. And it did.

The ESP’s dedicated I2C pins are on GPIO 21 and 22 for data and clock respectively. Some I2C implementations will use the microcontroller’s pullup resistors to pull the I2C bus lines high, so I tested that out by pulling the 10 KOhm resistors out. The ESP stopped getting data back instantly, so that answers that. Don’t forget your pullup resistors on the I2C lines and all is well. Otherwise, it’s just connecting up two wires, double-checking the I2C device address, and reading in the data. That was easy.

External Libraries

More than half of the reason to use Arduino is the wide range of external, add-on libraries that make interfacing with all sorts of hardware easy and painless. Many of these libraries are built strictly on top of the Arduino core, and should “just work”. Of course, when you’re actually coding this close to the hardware, nothing is going to be as portable as it is a few layers of abstraction higher up on your desktop computer. Let’s go test this hypothesis out.

El Cheapo IL9341 TFT Display

Mocking Arduino
Uno Lauging at ESP32

Since the SPI library works out of the box, the other various libraries that depend on it should as well, right? Well, kinda. I wasted an afternoon, and still failed. Why? I have a cheapo ILI9341 screen that only works with an old TFTLCD library, rather than with the nice Adafruit_ILI9341 libs. The former is so full of AVR-specific voodoo that it completely fails to compile, and is probably easier to re-write from scratch for the ESP32 than make work in its present form. The Adafruit library compiles fine, because it only depends on the SPI library, but it doesn’t work with my lousy screen.

Going repeatedly back and forth between these two libraries, my LCD experiment ended in tears and frustration: I couldn’t make either of them work. I scoped out the SPI data on a logic analyser, and it looked good, but it wasn’t drawing on the screen. At this point, a full line-by-line protocol analysis would have been needed, and that’s a few days worth of work. If I just wanted a running ILI9341 driver, I would go grab [Sprite_tm]’s NES emulator demo and use the one there, but it’s not Arduinified yet, so it’s out of bounds for the scope of this article.

DHT22 Humidity and Temperature Sensor

dscf8971
The Way It Should Work: Three Wires and Ten Lines of Code

Seeking a quick-and-dirty success, and beaten down by hours of hacking away for naught, I pulled a DHT22 sensor out of the eBay bin, and cloned Adafruit’s DHT library. Of course it didn’t compile straight out of the box, but there were only a couple of things that were wrong, and both turned out to be easily fixable.

ESP32’s Arduino didn’t have a microsecondsToClockCycles() function yet so I commented it out, multiplied by 240 MHz, and left a hard-coded constant in my code. This value was just used for a timeout anyway, so I wasn’t too worried. There are also some timing-critical code sections during which the Adafruit code uses an InterruptLock() function to globally enable and disable interrupts, but these functions weren’t yet implemented, so I just commented it all out and crossed my fingers.

After reassigning the data pin to one of the ESP32’s free ones (GPIO 27, FWIW), it compiled, uploaded, and ran just fine. I now know exactly how hot and humid it is up here in my office, but moreover have had a quick success with an Arduino external library, and my faith is restored.

Lessons from the Libraries

I suspect that these two examples are going to be representative of the ESP32-Arduino experience for a little while. Oddball hardware is going to take some time to get supported. Highly optimized libraries with cycle-correct timings or other microcontroller-architecture specific code in them will need to be ported over as well, despite being “Arduino” code. If you’re a code consumer, you’ll just have to wait while the wizards work their behind-the-scenes magic.

But there will also be a broad group of libraries that are written in a more-or-less device-independent way, and these should be easy enough to get working within fifteen minutes or so, as with the DHT sensor library. If you’re willing to compile, read the errors, and comment out or fix whatever shows up, some codebases will work in short order.

What’s Next? Turning Servos

Given that the Arduino-ESP32 port is brand new, indeed it’s still in progress, there is a lot of work for the community to do in getting it up to speed. Suppose that you need to drive a lot of servos, but the “Servo” library isn’t implemented yet. You’re an impatient coder. What to do? Get hacking!

The good news is that the Arduino-ESP32 libraries themselves are full of hints and examples for getting started. Open up the ESP32-specific directory that you cloned from GitHub. The usual *.cpp files provide the standard Arduino core functionality. The esp32-hal-xxx.h and esp32-hal-xxx.c files are chip-specific, and a tremendous help in taking advantage of the chip’s stranger options. For instance, esp32-hal-matrix.* gives you nice and easy access to the pin-routing matrix, which is a daunting task if you’re starting just from the datasheet.

scope_23
Spot-On and Jitter-Free

But let’s get back to servos. The ESP32 chip has an intriguing hardware LED PWM peripheral that lets you assign up to sixteen channels to individual LEDS, specify the PWM frequency and bit-depth, and then control them by appropriately setting bits in hardware registers. If you think this would be hard to do by hand, you’d be right. The esp32-hal-ledc.* files provide helper functions to set up the hardware PWM generator, and with these libraries, getting a 16-bit LED fade in straight C or “Arduino” is easy. But our sights are set on servos.

To drive a hobby servo, one needs pulses between 1,000 and 2,000 microseconds each, repeated every twenty milliseconds or so. Setting the repetition rate to 50 Hz takes care of the first part, and each count is 20 ms / 65,635 ticks long, or roughly 0.3 microseconds. Setting the PWM width value to something between 3,300 and 6,500 generates pulses in the right ballpark, and my servo ran jitter-free (and a clean signal was confirmed on the oscilloscope). Here’s all it took:

#include "esp32-hal-ledc.h"
void setup() {
   ledcSetup(1, 50, 16); // channel 1, 50 Hz, 16-bit depth
   ledcAttachPin(22, 1);   // GPIO 22 on channel 1
}

void loop() {
   for (int i=3300 ; i < 6500 ; i=i+100){
    ledcWrite(1, i);       // sweep the servo
    delay(100);
   }
}

That wasn’t so hard, was it? It’s not “Arduino”-style — there’s no objects or classes or methods anywhere in sight — but thanks to a straightforward and well-written hardware abstraction layer, using the very complicated peripherals is made pretty simple. Kudos to [me-no-dev] for his work on the back-end here. The HAL inside the Arduino libraries is currently the best source of code examples on many of the chip’s more esoteric and interesting peripherals.

Conclusion?

The short version of my dive into Arduino-esp32 is that there’s a lot here, even though it’s not done yet. Blinking LEDs and other simple GPIO is a given, and the core communication libraries that are already implemented worked for me: GPIO, WiFi, SPI, and I2C are up and running.

Non-core libraries are hit and miss. I suspect that a lot of them will work with just a little bit of tweaking. Others, especially those that are architecture-dependent, may not be worth the effort to port and will need to be re-written. The ESP32 has a bunch of interesting and innovative hardware peripherals onboard and there’s certainly no Arduino libraries written for them yet, but there’s some great HAL code hidden away in the Arduino-ESP32 codebase that’ll give you a head start. We could get lost in there for hours. Time to get hacking!

The ESP32 is still a new chip, but orders should be coming in soon. Have one? Want to see us put other libraries or languages through their paces? Let us know in the comments.


Filed under: Arduino Hacks, Engineering, Featured

coverNicole Grimwood is working towards a dual degree in engineering from Columbia University and liberal arts from Scripps College.

Read more on MAKE

The post Interview: NIcole Grimwood on Electronics (and Cake) appeared first on Make: DIY Projects, How-Tos, Electronics, Crafts and Ideas for Makers.

Mag
08

Swedish Engineering Prize goes to David Cuartielles!

Announcements, Arduino Verkstad, engineering, Featured, prize, Sweden Commenti disabilitati su Swedish Engineering Prize goes to David Cuartielles! 

awardDavid

We are happy and proud to announce that  David Cuartielles, co-founder of Arduino and CEO of Arduino Verkstad, got this year’s prize from the Swedish Electrical and Computer Engineers’ National Association (Svenska Elektro- och Dataingenjörers Riksförening) SER. The association awards an engineering student and a senior engineer that works with electrical, data and IT technology. The senior engineer has to lead an important role in smart and sustainable technological development:

This year the award goes to David Cuartielles from Malmö University for his open source platform Arduino, which is based on easy to use hardware and software to develop interactive projects.

This award – David said – has been possible thanks to the kind support of the Arduino familyMalmö Högskola and most importantly, the open source community.

Ott
10

A Baby Monitor goes open source: interview to the team

Africa, arduino, Biomedical, education, engineering, kenya, Medical, open source Commenti disabilitati su A Baby Monitor goes open source: interview to the team 

Open source Baby Monitor

Last August, a team composed by researchers coming from  Research Center E. Piaggio of University of Pisa and FabLab Pisa, went to Nairobi to work at the Summer School developing an Open Source Baby Monitor for OS4BME (Open Source for Biomedical Engineering). Arduino supported the project with some hardware and following their adventure in Africa.

Arti Ahluwalia (Professor of Bioengineering), Daniele Mazzei and Carmelo De Maria (Biomedical Engineers, co-founders of FabLab Pisa and researchers at the Center) are now back in Italy and I interviewed them as this project raised interest from the open source community.

Open source Baby Monitor

Which tools did you use to prototype the baby monitor and why they were useful?

We decided to use open source tools to design and prototype the baby monitor because we believe economic barriers can’t stop the creative process. Our results will be the starting point for future projects, following the open source philosophy. A baby monitor is composed by a 3D-printed mechanical frame, an electronic board and a control software. Thus, in order, we used FreeCAD for mechanical design, MeshLab to analyze the quality of the mesh, Slic3r (http://slic3r.org/) to generate the machine code, Pronterface to send commands to a Prusa Mendel RepRap. The brain of the baby monitor, electronic and software, is based on Arduino.  MediaWiki helped us in documentation. As you can see the list is quite long, and the final result is a credit to all the components. This interview gives us the opportunity to say thank you to all the people who work in these projects.

Open source Baby Monitor

In which way the participants played an active role in the workshop?

From the first day, participants were divided into working groups in order to facilitate interaction. The groups were given specific tasks related to documentation and note taking, so as to collect all the notes for the final wiki document. On the third day the groups were split up into practical working groups according to the interests of individuals, whence they were given an aspect of the baby monitor to design, develop and realise.

What type of collaborative processes did you start and what are the next steps (documentation, sharing..etc)?

The processes involved a sort of twinning between Fablab Pisa and Fablab Nairobi. We delivered the Arduino donated kits to the Fab Lab Nairobi and Kenyatta University. FabLab Pisa introduced the FabLab Nairobi to the IOTPrise project of University of Pisa. Being part of the IOTPrise community FabLab Nairobi became beta tester of UDOO, an open hardware low-cost single-board Android/Linux ARM computer with Arduino-compatible integration.

As the importance of the action, particularly as regards the need to develop excellence and sustainability in Biomedical Engineering higher academic was noted by all. Thanks to our technical guidance and previous experience with human resource building in developing countries, all academic participating academic institutions have decided to pool their resources towards the creation of an African Biomedical Engineering consortium, dedicated to sharing curriculum development, staff and student training and teaching materials.

You started the this challenge with some expectations, what happened of unexpected?

We had expected the action to be an immediate success, and it was. Most students and staff were unaware of the existence of tools such as Arduino, FreeCad, Slicer, Media Wiki etc, let alone the power and implications of open source design and prototyping. The course was instrumental in bringing this knowledge to the participants, and their keen interest throughout the introductory part, particularly on 3D printing and rapid prototyping was apparent. We also expected immediate follow ups (requesting more information and documentation) from all participants. Actually this did not happen. We do need to be sensitive of cultural differences and of the fact that our priorities may not be the same as those of the participants.

Dealing with healthcare is not an easy task, how are you meeting with regulatory and performance standards?

As Biomedical Engineers, we were fully aware that biomedical devices must ensure patient safety and efficacy above all. Part of the course was purposely dedicated to biomedical device standards, regulation and performance, and this is what made the action unique with respect to others such as cooking hacks etc.

How can people collaborate now?

One of the goal of OS4BME  project was to create a common language, a shared way of thinking on which build future objectives. African engineers can use now our same instruments, and we know by first hand which are the real needs, desires and enthusiasm of African people: these facilitate an active collaboration. As aforementioned, FabLab Nairobi is involved together with FabLab Pisa in the IOTPrise project community.
In parallel, the University of Pisa is working with the ABEC and Boston University to raise funds for further courses and student and staff exchange. I have to stress that our (or at any rate my) objective is enable African countries to manage, develop and maintain their own medical equipment by transferring Biomedical expertise to African universities.

Baby Monitor Open Source

Learn more on their wiki

See more pictures on the Fablab Pisa website

Read the press release of the University of Pisa (in italian)



  • Newsletter

    Sign up for the PlanetArduino Newsletter, which delivers the most popular articles via e-mail to your inbox every week. Just fill in the information below and submit.

  • Like Us on Facebook