Raspberry Pi Or Arduino - Page 1
Forum section: electronics / general

author: German_EE
author_rank: Super Contributor
timestamp: October 03, 2018, 06:15:06 pm
content: OK, deep breath because the flame wars here could be spectacular.I want to build a project that has a small computing requirement including reading a number of eight bit ports and outputting to a text based VFD display after some calculation. The CPU board needs to be 32-bit as I will be handling some large numbers and whatever processor I pick I will need to learn from scratch again as (up to now) I have been using PICAXE. System I/O through a USB port will be required.So, Arduino or Raspberry Pi, and please explain your answer

author: andersm
author_rank: Super Contributor
timestamp: October 03, 2018, 06:28:29 pm
content: Do you want to write C against the bare hardware (Arduino), or do you want to use higher level languages under an operating system (Pi)?

author: donotdespisethesnake
author_rank: Super Contributor
timestamp: October 03, 2018, 07:15:13 pm
content: Quote from: German_EE on October 03, 2018, 06:15:06 pmNot sure what an 8-bit port is, are these discrete IOs?QuoteWhat is the display interface? SPI, I2C, Ethernet??What calculations? How fast?QuoteEven 8 bit Arduinos can handle 64 bit values...depends on many Flops you need.QuoteUSB host or device? What device class?QuoteInsufficient data...but sounds like it can be done with an Arduino.

author: Ian.M
author_rank: Super Contributor
timestamp: October 03, 2018, 07:31:38 pm
content: Even a low end 8 bit AVR or PIC can easily do 32 bit maths in C.The question is: how much maths and how fast? Without hardware assistance, multiplication, and especially division are much more resource and CPU intensive than addition/subtraction. The cost of maths functions depends on their implementation e.g. number of terms in the series approximation and complexity of each term.If you specify the number of 8 bit ports to be read, whether or not there is a strobe or trigger that indicates 'data valid', the maximum update rate, and the mathematical calculation to be performed we would better be able to advise on a suitable platform.

author: jpb
author_rank: Super Contributor
timestamp: October 03, 2018, 07:47:45 pm
content: My understanding is that a Rasberry Pi and an Arduino are different beasts. The Rasberry Pi is geared for calculations and running programs but will be less precise in timing of inputs and outputs, that is it is not particularly designed for real-time interrupt handling.The Arduino is more designed for interacting with hardware but is less powerful for doing processing.

author: German_EE
author_rank: Super Contributor
timestamp: October 03, 2018, 08:16:10 pm
content: OK, an idea of the task1) Input 4 x 8 bits using an 8-bit port and some chip select lines. All signals at CMOS (74HC) levels2) Assemble these into a single 32-bit word3) Work out ((2^32) / input word) + stored offset), integer maths will be fine here4) Output the result to the display using either an SPI or I2C interface5) If required by an external command output the displayed number through the USB port to the PCI'm prepared to switch from BASIC to C as the maths requirement is not too hard and speed is not really an issue as a displayed result that updates ten times a second will be just fine.

author: HB9EVI
author_rank: Frequent Contributor
timestamp: October 03, 2018, 08:31:07 pm
content: I don't want to talk too bad about the Pi, but for my general needs, they are too bleeding edge for reliable operation - both software and hardware.All over the years it turned out to be more reliable to interface any kind of peripherals either directly via USB/UART or USB/I2C to my server or to operate them by a Mcu, which - if needed - can be controlled by PC as well.For serious needs I'd rather take an Apu or Alix board from pcengines than a PiPi is nice and fun for experimenting though

author: TK
author_rank: Super Contributor
timestamp: October 03, 2018, 08:38:03 pm
content: One point to consider is boot time. An arduino or microcontroller based system will be ready to run in fractions of a second, while a Pi needs a lot of time to boot from the SD card.Another factor is that the Pi requires a clean shutdown to avoid filesystem corruption, while a microcontroller based system will reboot without issues.

author: nfmax
author_rank: Super Contributor
timestamp: October 03, 2018, 09:29:07 pm
content: Raspberry Pi GPIO's are 3.3V only, so you may be better off with an Arduino just for that reason.

author: donotdespisethesnake
author_rank: Super Contributor
timestamp: October 03, 2018, 09:31:55 pm
content: Quote from: German_EE on October 03, 2018, 08:16:10 pmI will assume that means you will send data over a USB serial link, and some code on the PC will read the serial port and display the data.QuoteI would definitely suggest Arduino, because it is well within performance and a lot easier to program the external IO. If I had the parts, it would probably take a couple of hours to wire up on a breadboard, write the code and get it working. For someone who has experience with PICAXE, I think it would be quite straightforward, probably the learning curve will be in getting to grips with C/C++.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: October 03, 2018, 09:54:50 pm
content: Quote from: German_EE on October 03, 2018, 06:15:06 pmDepends on power requirements. If Battery Powered... Arduino or ESP32... if powered from a mains supply... Pi.

author: brucehoult
author_rank: Super Contributor
timestamp: October 03, 2018, 09:55:00 pm
content: Quote from: German_EE on October 03, 2018, 08:16:10 pmTen times a second. No significant internally stored data.The smallest AVR or PIC will do the job just fine. And would, even if it was 100 times a second. Maybe 1000. Even using the much maligned Arduino IDE and libraries for everything.The 32 bit division will take a while -- maybe as much as 20 us? But you just declare your variables as "unsigned long" in C and the compiler will sort it out.A Raspberry Pi is huge overkill for this. But it would work too.

author: cv007
author_rank: Frequent Contributor
timestamp: October 03, 2018, 10:56:09 pm
content: Or maybe use what you already know- picaxe. I don't know anything about picaxe, but if it can't handle what you describe, it must be quite limited.Maybe you just need to rethink the problem a little- for example, if you are short on pins you can use 4 parallel to serial shift registers (74HC165 for example, <$0.40ea) and grab the whole 32 bits at once, shift them all in and you have a 32bit value that was taken in a single point in time (may not be important or may be- don't know). You still need some pins, but I would guess only about 4.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: October 04, 2018, 12:45:49 am
content: I do not have much love for neither RasPi nor Arduino.RasPi, is dirty and to far away from the open source software as long as they keep using the Broadcom chips and binary blobs.But there are a pretty big number of other ARM Linux boards available at comparable prices."Arduino" has never been meant to be used by programmers, but by "artists" whatever that means."arduino" gobbles up all your hardware so you can not use it anymore in the way you want."arduino" makes me particulary sad because it teaches bad programming techniques to hundreds of thousands of new programmers.It is very easy to get your first blinking led project to work without prior knowledge of uC's, and hats of for that, but after some time you bump into the artifical limits of the arduino stuff.If only they had the sense to not pre-instantiate objects for all the peripherals and let the choice to the user.It could have been such an excellent platform for teaching C++.Back to your project:You should ask yourself:Does my project benefit from a full blown linux system?Do I need stuff like:- HDMI / VGA output.- Complete file system.- PC keyboard / Mouse / GUI- Multiple MB of RAM for intermediate data.- GHz scale processor power.If you need stuff like that, then one of the many Linux single board computers may well suit your needs.If you just want to do some calculations which are easily handled by a <100MHz microcontroller, combined with some SPI / UsART and other peripherals readily available on a microcontroller then it is very likely that a single chip microcontroller is the better option for you.Actually, I'm surprized you ask.You say you have experience with dsPIC, so you should have a reasonable good Idea of what you can do with a microcontroller and what you need for your project.Ah. Now I realize I fell for it.You are just trolling and trying to start some flame war.What a waste of effort from well meaning people.

author: brucehoult
author_rank: Super Contributor
timestamp: October 04, 2018, 01:00:07 am
content: Incidentally, calculating 2^32/input_word directly actually needs 64 bit integers. Or at least bigger than 32 bit :-)However, (2^32-1)/input_word can be done with standard 32 bit (unsigned) integers.The only values of input_word for which the answer is different are the powers of two -- the numbers for which exactly one bit is set. In which case the correct answer is 1 larger than you get from (2^32-1)/input_word.So you can do something like:Code:unsigned long calc(unsigned long input_word){unsigned long result = 0xfffffffful/input_word;if ((input_word & (input_word - 1)) == 0) ++result;return result;}

author: kaevee
author_rank: Regular Contributor
timestamp: October 04, 2018, 01:14:15 am
content: Quote from: German_EE on October 03, 2018, 06:15:06 pmYou may consider using a TI Launchpad or ST Discovery board instead of Arduino board. Unlike Arduino, they provide you debugging out of the box.Checkout TI MSP-EXP430FR5994 launchpad based on MSP430FR5994 available for $17 and TI usually ships for $6. Here are the list of features (copied from TI)EnergyTrace++ Technology available for ultra-low-power debugging40-pin LaunchPad kit standard leveraging the BoosterPack ecosystemOn-board eZ-FET debug probe2 buttons and 2 LEDs for user interactionOn-board micro SD CardSuper Capacitor (0.22 F)TI ClaimsThe MSP430FR5994 includes the new Low-Energy Accelerator (LEA). This new hardware module delivers fast, efficient, low-power vector math acceleration commonly found in digital signal processing (DSP) applications. This makes it easy for the MSP430 to process incoming analog data in real-time. With benchmarks that outpace 32-bit ARM® Cortex®-M0+ MCUs by more than 40x, this nimble MCU delivers performance with exceedingly low power consumption.You may also checkout ST discovery boards which pack lot of processing power.

author: rjp
author_rank: Regular Contributor
timestamp: October 04, 2018, 01:15:10 am
content: a 555 timer should handle this fine.

author: German_EE
author_rank: Super Contributor
timestamp: October 04, 2018, 03:13:53 pm
content: Thank you for the replies so far. The main reasons why I had to switch from the PICAXE system are twofold, firstly there is still no decent way of doing 32-bit maths on the system without a weird (and slightly unobtainable) maths coprocessor, and secondly the entire PICAXE ecosystem seems to be dying having been beaten to death by Arduino and Raspberry Pi between them. So, when in Conrad on Tuesday night I looked for microcontrollers it seemed to be a straight choice between the two main players.To Doctorandus_P, I must admit that it takes a certain amount of chutzpa to accuse someone with nearly two thousand posts of being a troll but you managed itFortunately after a working life of nearly forty five years I've developed a reasonably thick skin.The math examples in some of the posts is interesting and I am not sure why I would need 64-bits. 2^32/n where n is a number somewhere between 1 and 2^32 can still be done in 32 bits (I think) but then I'm an electrical engineer who is still learning this stuff.The decision is made, I will get an Arduino module this weekend and dive headlong into the wonderful world of C/C++ programming. After learning Ladder Logic and BASIC this will be my third language.

author: donotdespisethesnake
author_rank: Super Contributor
timestamp: October 04, 2018, 09:35:03 pm
content: Quote from: German_EE on October 04, 2018, 03:13:53 pmAn unsigned 32 bit can hold a value from 0 to 2^32-1. Maybe the difference is not significant for your application and you are being approximate. I don't how many digits of precision you intend to display, but you could probably use float instead.

author: Dielectric
author_rank: Regular Contributor
timestamp: October 05, 2018, 01:08:40 pm
content: Not everything in the Arduino universe is AVR-based. The Teensy 3 is fully supported within the ecosystem and is also a pretty nice 32-bit Cortex M4, and the bigger ones have a floating point unit (M4F). It doesn't sound like you need shield support so the smaller form factor may even be a benefit.

author: GeorgeOfTheJungle
author_rank: Super Contributor
timestamp: October 05, 2018, 01:24:13 pm
content: Quote from: German_EE on October 03, 2018, 08:16:10 pmAn arduino uno can do all that just fine, me thinks.Quote from: German_EE on October 03, 2018, 08:16:10 pmThe PC will see it as a serial port.A Raspberry Pi takes ages to boot, compared to an arduino.

author: Fungus
author_rank: Super Contributor
timestamp: October 05, 2018, 01:34:07 pm
content: Quote from: German_EE on October 03, 2018, 06:15:06 pmArduino can handle 32-bit numbers, will be alotsimpler learning curve, will boot very quickly (no need to load an entire graphical OS).I guess it all depends on what "large numbers" are.

author: German_EE
author_rank: Super Contributor
timestamp: October 05, 2018, 07:44:54 pm
content: In this case 'large' is an integer somewhere between 1 and (2*32) - 1.Until I started digging I didn't realize that the Arduino processors are mostly eight bit and the ability to handle numbers larger than 255 is done through the compiler! This is damn annoying as it means that Revolution Education (the people who run PICAXE) could have introduced thirty two bit variables years ago just by modifying the IDE and the compiler. OK, it would run slower, but it would still be useable.

author: taydin
author_rank: Frequent Contributor
timestamp: October 05, 2018, 08:02:25 pm
content: The biggest reason to go PI is the GNU/Linux operating system. If you want to leverage all of the possibilities that the GNU/Linux can give, and you have some experience with GCC (GNU Compiler Collection), then PI is the way to go.But if this is a one off job, and you want to write some code and be done with it, then Arduino is the way to go.

author: donotdespisethesnake
author_rank: Super Contributor
timestamp: October 05, 2018, 09:34:57 pm
content: Quote from: German_EE on October 05, 2018, 07:44:54 pmHmm, slower, but also use more RAM and Flash, unless used sparingly. The top end PICAXE has 16kB Flash and 1280 bytes RAM, compared to Arduino Uno which is 32kB Flash and 2kB RAM, and then there is the Arduino Mega which has 256kB Flash and 8kB RAM.Writing compilers is not entirely trivial, Arduino leverages the gcc suite which already had AVR support in it, and the Java IDE was also not written by them, so they started with a good base of powerful software, and they have spent their effort tailoring the system for Arduino. I think that the PIXAXE software is proprietary and all written in house, as far as I know.Unless you are doing some heavy number crunching, native 32 bit is not that big a deal, but there is Arduino Due which is 32 bit Cortex M3 at 84MHz. I think you will be pleasantly surprised by the power and ease of the Arduino ecosystem if you are coming from a PICAXE background.

author: brucehoult
author_rank: Super Contributor
timestamp: October 05, 2018, 11:58:35 pm
content: Quote from: German_EE on October 05, 2018, 07:44:54 pmTechnically true, but not exactly challenging.If the program has a 32 bit variable stored in registers A,B,C,D and the compiler wants to add a 32 bit variable stored in registers a,b,c,d to it then it's just a matter of emitting:Code:add A,aadc B,badc C,cadc D,dFour instructions, eight bytes of code, four clock cycles at your 16 MHz (usually).Compare that to the good old 6502, where those things are in, at *best* zero-page memory locations, not registers.Code:clclda Aadc asta Alda Badc bsta Blda Cadc csta Clda Dadc dsta DThirteen instructions, *twenty five* bytes of code, thirty eight clock cycles at typically 1 MHz.The AVR in the Arduino is 8-bit, but it's (for this operation) 152 times faster than the 6502. And the code is three times smaller.A heck of a lot of software on 6502 machines such as the Apple ][ used not only 32 bit arithmetic, but 32 bit FLOATING POINT. Done in software.And almost nothing was actually done directly in the bulky machine code, but instead common operations were wrapped into some kind of simple interpreter, whether BASIC, Pascal, Sweet16, or threaded code (Forth/Logo style).

author: martinjaymckee
author_rank: Contributor
timestamp: October 06, 2018, 06:42:31 am
content: I think the standard Arduino is a good fit for this. Over the years I have done a number of projects (using both the Aruduino IDE and the GCC compiler/libraries directly) which have done control with loop speeds over 100Hz and done a fair amount of processing (filters and PID) per loop. The Arduino libraries can certainly get annoying at times and there are things (like single pin digital read/write) which are insanely inefficient. But it is possible to get a project up and running very quickly. One thing to remember is that you can always grow beyond the "basic" Arduino libraries. The compiler is just standard C++ with a custom preprocessor at the front. Now, granted, the preprocessor causes trouble with some C++ constructs sometimes.... Anyhow, I think you've made a good choice for your application.I would certainly recommend looking at Arduino tutorials (and the built-in examples). I would not, however, recommend viewing them as examples of good programming. As has been said before here, Arduino tends to train poor programmers. Honestly, when learning the language I think it's better to have a C++ compiler on your computer so that you can write short test programs with specific constructs. Then you can move that syntax into Arduino. One of the biggest problems with programming in "Arduino" style is the rampant use of delays. In the workshops I taught I would start with delay() on the first LED blink and then immediately show ways to get the same blink effect without blocking the processor. Unfortunately, Arduino doesn't always play well with using the hardware interrupts (as mentioned above) as the run-time already uses a couple of the timers. There are ways to do things well though, even within the constraints of the Arduino environment.Cheers,Martin Jay McKee

author: brucehoult
author_rank: Super Contributor
timestamp: October 06, 2018, 08:46:15 am
content: Quote from: martinjaymckee on October 06, 2018, 06:42:31 amIt's not *that* bad. The main problem I think is converting from logical pin number to port and offset very time. It's a few us at worst.QuoteWhat problems?As far as I know, all the Wiring preprocessor for C++ does is gather up all the function prototypes and put forward declarations at the start of the program, so you don't have to worry about order of functions. And then jam a #include on the start.The Wiring preprocessor for Java just wraps everything in a class and puts an import at the top (as method order already doesn't matter in Java).QuoteYes, it's a shame. It's really not that hard to convert the standard...Code:void setup() {pinMode(LED_BUILTIN, OUTPUT);}void loop() {digitalWrite(LED_BUILTIN, HIGH);delay(1000);digitalWrite(LED_BUILTIN, LOW);delay(1000);}... to ...Code:const int LEDOnTime = 1000;const int LEDOffTime = 1000;int LEDState = LOW;long nextLEDTime = 0;void setup() {pinMode(LED_BUILTIN, OUTPUT);}void loop() {long now = millis();if (now - nextLEDTime >= 0){if (LEDState == LOW){LEDState = HIGH;nextLEDTime += LEDOnTime;} else {LEDState = LOW;nextLEDTime += LEDOffTime;}digitalWrite(LED_BUILTIN, LEDState);}}(there's a slight hack here .. millis() actually returns unsigned long, but to get proper behaviour on the 49.7 day wrap-around we need a signed result from the subtraction, so it's easiest just to jam millis() into a signed long.)This is easily extendable to an arbitrary number of things that need to be timed. If there are really a lot of them then it would be better to build a binary heap-based priority queue. That's pretty easy but for some reason no one seems to have bothered to do it for Arduino. You could even make it interrupt driven,.

author: brucehoult
author_rank: Super Contributor
timestamp: October 06, 2018, 08:53:08 am
content: Quote from: donotdespisethesnake on October 05, 2018, 09:34:57 pmIf you want some real number crunching power then there is the HiFive1 with a 32 bit RISC-V processor at 320 MHz. It has 6x less SRAM than the Due (16 kB) but 32x more flash for your program code (16 MB).https://www.crowdsupply.com/sifive/hifive1https://www.digikey.com/products/en?keywords=hifive1https://nz.mouser.com/ProductDetail/Crowd-Supply/cs-hifive1-01?qs=%2fha2pyFaduiYWq09B7sm7wDmAaLBQ5QCD7BSHMmGALI%3d

author: donotdespisethesnake
author_rank: Super Contributor
timestamp: October 06, 2018, 09:31:03 am
content: Quote from: brucehoult on October 06, 2018, 08:53:08 amThat's a total waste of time then! But thanks for the spam.

author: GeorgeOfTheJungle
author_rank: Super Contributor
timestamp: October 06, 2018, 09:40:47 am
content: Quote from: brucehoult on October 06, 2018, 08:53:08 amThe ARM "bluepill" arduino is hard to beat at ~ $2:http://wiki.stm32duino.com/index.php?title=Blue_Pillhttp://wiki.stm32duino.com/index.php?title=Installationhttps://robotdyn.com/stm32f103-stm32-arm-mini-system-dev-board-stm-firmware.htmlQuote

author: brucehoult
author_rank: Super Contributor
timestamp: October 06, 2018, 10:06:56 am
content: Quote from: donotdespisethesnake on October 06, 2018, 09:31:03 amStill a lot of RAM for an Arduino, the majority of which sold have 2 KB -- which is itself enough for one hell of a state machine. It all depends on what your task at hand is. Choice is good.

author: brucehoult
author_rank: Super Contributor
timestamp: October 06, 2018, 10:09:40 am
content: Certainly that's very nice for $2 or $3.