Bare metal or Raspberry Pi, pro's and con's - Page 1
Forum section: electronics / general

author: DVX
author_rank: Contributor
timestamp: July 17, 2017, 05:36:27 pm
content: I am now close to completing a long standing hobby project, it's PIC32 based and coded in C. It has a DS3231 RTC which is updated for time and date from a Nano GPS module, so very accurate. LCD back-lighting is controlled by a TSL2561 and a BME280 is used to generate temp, air-pressure and humidity. Output is via a TFT 320 x 240 with a user menu system and moving gauges for the BME280 data. So lots of I2C coms and real time TFT updating as it has no frame buffer. It's helped me learn C and use multiple sensors.There are a number of higher level platforms, like the RPi which have libraries for many if not all the sensors used, so I wonder what are the pro's and con's of designing a similar system on a RPi? Screen updating should be faster, likely hardware costs could be lower, but I am not sure how deterministic it would be compared to a 32bit processor, with a timer ticking away at 1ms, reading ports. My PIC32 from power up takes less than a second to display the user menu and first screen, a RPi is an SD card boot. But perhaps there is a point a more powerful hardware platform makes more sense than a dedicated processor running with no operating system?

author: DVX
author_rank: Contributor
timestamp: July 18, 2017, 02:22:36 pm
content: Thanks evb149 lots of good points to consider in your reply.Looking at a number of RPi sites the main focus looks to be coding in Python with this being interpreted in real time. What might exist is a good GUI interface for programming in C, which can then write the code to the SD card directly, maybe even residing on the Pi. I would like to stay with C and increase my coding experience and not move over to Python just at this stage.The BeagleBone platform with eMMC flash to boot Linux might get closer to a faster boot time, so for future projects I will also consider this.I have PPS working already and this is used to update the RTC periodically, its amazing what data can be read from a GPS unit with builtin antenna and the system indoors. The GPS code will be revisited soon to parse altitude and add this to the displayed info. Your comments for timezone settings are interesting, but to keep things simple the user inputs the timezone from one of the menu's and this is stored in flash, not ideal but timezone rule/database as you mention is complex. Even having day light saving hours automated isn't straight forward with the dates for the changes being different, in different countries, at least here in the UK the GPS time is correct after October.I will study more MCU platforms and see if some have implemented frame buffers and have good library support as this could be a good way forward. One is Teensywww.pjrc.comthey have a 180MHz Cortex-M4, pity it is Arduino based but then perhaps I should be more open minded to this.

author: alm
author_rank: Super Contributor
timestamp: July 18, 2017, 02:37:57 pm
content: If you want the best of both worlds (and the complexity of both worlds), you could consider using the BeagleBone Black which has a few programmable real-time units (simple MCU cores) that can handle low-latency work.You could develop an RPi application using QT or GTK in C(++). Just because all the cool kids use Python does not mean you have to. I would prefer C++ with QT for GUI development over C with GTK.

author: Howardlong
author_rank: Super Contributor
timestamp: July 18, 2017, 07:38:09 pm
content: Another aspect is power consumption, not only will a PIC32 draw much less power in the processing core anyway, but you have a lot more control on bare metal, and you can be much more confident of understanding any side effects of applying power management strategies ahead of time rather than relying much more on empirical methods. Depending on your application this may not be a problem, but for small battery powered devices that might not be the case.

author: NorthGuy
author_rank: Super Contributor
timestamp: July 19, 2017, 02:46:00 am
content: You may consider the newest PIC32MZ DA which has a graphics controller and 32MB of RAM.

author: Sal Ammoniac
author_rank: Super Contributor
timestamp: July 19, 2017, 03:16:00 am
content: I would like to do bare metal development on a Pi, but the thing stopping me is the lack of documentation for the CPU. Broadcom seems to treat the datasheet and reference manual as Top Secret documents.

author: alm
author_rank: Super Contributor
timestamp: July 19, 2017, 03:42:32 am
content: Trying to use the RPi for bare metal seems like trying to drive a square peg in a round hole. For example, for the processor used in the BBB (no, I am not paid by TI), TI has no problem providingdetailed technical information. Why stick with Broadcom if they clearly do not want your business?

author: cdev
author_rank: Super Contributor
timestamp: July 19, 2017, 04:00:31 am
content: Maybe they are? I could see that happening. Look at your own .sig!Quote from: Sal Ammoniac onTodayat 21:16:00

author: timb
author_rank: Super Contributor
timestamp: July 19, 2017, 05:19:47 am
content: Quote from: DVX on July 18, 2017, 02:22:36 pmThat's not entirely true. Python doesn't work like BASIC (where it's interpreted line by line). Instead, it's compiled to bytecode at runtime and runs under the Python VM.That can actually be quite fast depending on the language (Lua, for instance, can be just as fast as a compiled C program in a lot of cases when used with LuaJIT). Python 2.7 is about middle of the road speed wise (though Python 3 can be significantly faster in some areas). That said, there's a way to get the speed of C from Python: Cpython. Basically, you can write the speed/performance critical part of your code in C, compile it and then simply import it into your Python program (just like any other Python module). It's very powerful, and easy, too!If you can split your program up into multiple chunks that can perform work independently of each other, you can use the built-in threading and multiprocessing modules (the former runs as a single process with threads; the threads working during idle periods of the main loop; the latter actually creates separate processes to run the code in). Both are actually really easy to use (like everything else Python).In a few weeks I went from knowing basically no Python to writing my own library that talks to a PCB I designed over I2C (and reads a fan tachometer pulse directly from the GPIO), a daemon program that uses said library to serve data up from the hardware over a TCP socket using ZMQ and a client program that talks to the daemon and lets the user interact with the data through a multi-page Ncurses based UI.There's no way I could have done it that quickly in just C.In my case, one of the keys to speedy GPIO access was to use a low level C based daemon (the aforementioned pigpiod, which has C, Python and other libraries available) which gives you microsecond level read access to the GPIO, along with DMA based writes and high resolution PWM.Anyway, my point is, don't count Python out. It's not BASIC and the Pi has plenty of horsepower. (Though, in your case an MCU may still be the way to go, depending on if just need to control a simple character LCD or small GLCD, or a large color graphic LCD. If it's the latter, an embedded system like the Pi would be a lot easier!)

author: Mechatrommer
author_rank: Super Contributor
timestamp: July 19, 2017, 06:37:40 am
content: Quote from: timb on July 19, 2017, 05:19:47 amwhere do you get BASIC is interpreted language?

author: 3db
author_rank: Frequent Contributor
timestamp: July 19, 2017, 07:51:50 am
content: @MechatrommerPerhaps because the BASIC interpreter was ubiquitous compared to BASIC compilers.

author: tszaboo
author_rank: Super Contributor
timestamp: July 19, 2017, 02:01:46 pm
content: Quote from: Sal Ammoniac on July 19, 2017, 03:16:00 amPreatty much. No datasheet means, you dont know what you are doing.Try configuring an just a measly ATMega UART without any library, without using the datasheet.It will be like this:Write 0x23000015 to register 0x0012000018.XOR 0x0012000019 value with 0x000010000 and write it back.

author: timb
author_rank: Super Contributor
timestamp: July 19, 2017, 02:49:07 pm
content: Quote from: Mechatrommer on July 19, 2017, 06:37:40 amBecause in pretty much all cases, first generation BASIC was interpreted. Second generation BASICs (starting with GW-BASIC) did tokenize the program before running it, but was still interpreted on the fly.Stuff like VisualBasic does compile, but that's BASIC in name only.

author: alm
author_rank: Super Contributor
timestamp: July 19, 2017, 03:23:11 pm
content: Quote from: timb on July 19, 2017, 02:49:07 pmAnd even then. VB6 has been obsolete for quite a number of years. VB.NET is C# with some syntactic sugar to make it resemble classic VB. I guess there are still some compilers like PowerBasic that are supported, but they are decidedly niche. The most popular implementation might very well be TI-BASIC for graphic calculators (although you could argue about how much it resembles BASIC). TI-BASIC is interpreted, as far as I know. The execution speeds certainly suggests that.

author: stevelup
author_rank: Regular Contributor
timestamp: July 21, 2017, 06:28:04 pm
content: STM32 would be good for this project. In particular, the STM32F429I-DISCO board would be a great starting point for development. It's very cheap for what it is.Proper framebuffer based graphics but in a hand solderable package.

author: Bruce Abbott
author_rank: Frequent Contributor
timestamp: July 22, 2017, 07:57:36 am
content: Quote from: timb on July 19, 2017, 02:49:07 pmYou forgotQuickBASIC. The modern open-source equivalent isFreeBASIC- which works on DOS, Linux, Windows and Xbox.BTW even early versions of Microsoft BASIC (supplied with most 'home' computers in the 80's) tokenized the program, but not very efficiently. It was optimized for interpreter size rather than execution speed, and run on slow 8 bit machines, which is why many people think that interpreted languages suck. But Python is also interpreted (after being tokenized and 'compiled').

author: DVX
author_rank: Contributor
timestamp: July 22, 2017, 05:04:33 pm
content: One reason for moving from an embedded system with no operating system to one that has, is networking. My current system is using Mikroe hardware and compiler and while it has an Ethernet Library, my humble PIC32 is now close to running out of processing time or at least become less responsive to inputs and slower at TFT updating. With networking the results of all my sensors could be displayed via a web-server.

author: C
author_rank: Super Contributor
timestamp: July 23, 2017, 08:33:35 pm
content: When you use something like a RPI that has an multi-tasking operating system, you lose the fine time control that something like a PIC32 can have,Some things can be done easy using a RPI, your list looks easy. On the other hand some things become a mess for the RPI. CNC & 3d printing are not bad examples where RPI is a fail. Some slow CNC machines are using the 8-bit AVR chips, should note that commercial CNC might use some slow limited chips like AVR but will have better main cpu. The AVR is such a system would be used for a task to take load off the main processor.Now if you look at Ethernet, it's good but not for real time with tight needs.For tight real time the interface is the CAN bus which is designed around sending events with priority. Just look at how the many CPU's care connected in cars.The great thing about these two (Ethernet & CAN) is the hardware defined start of a packet.USB is also has a hardware defined start of a packet. So a micro-controller that has a USB can use packets. When you use async serial then packets become hidden.With out hardware defined packets, software overhead increases to create a software defined packet again. PPP is one method of using IP packets over async serial.There is non great answer, but very many options.Look at your case, do you really need time zones local?Not hard to ask user.Your pic could ask the RPI, "what us the current offset for this time zone?"If PIC has Ethernet you might download the timezone database text file.After processing the PIC could be up to date.With Ethernet the PIC could become a local network time server.It could ask a network time server for the time if that helps.It could be interesting to look at the cost difference and ease to do the same project using an ESP32.Note that I said the CAN bus is event based packets.This makes it easy to use as modules to complete a task using many micro-controllers where you need better than Ethernet for real time.You could connect your PIC32 to an ESP32 and gain wireless Internet..Think most would use serial interface, but you should look at CAN bus.Look at changes CAN bus can give to PIC32.So there are places for more powerful micro-controllers doing real-time or standalone.Places for ones like ESP32Places for RPI's.....

author: Sal Ammoniac
author_rank: Super Contributor
timestamp: July 24, 2017, 04:20:57 pm
content: Quote from: DVX on July 22, 2017, 05:04:33 pmWhat PIC32 are you using? If it's a PIC32MX you could try a PIC32MZ, which runs up to 250 MHz and is much faster than an MX.