Author Topic: Raspberry Pi Or Arduino  (Read 4179 times)

0 Members and 1 Guest are viewing this topic.

Offline German_EETopic starter

  • Super Contributor
  • ***
  • Posts: 2399
  • Country: de
Raspberry Pi Or Arduino
« on: October 03, 2018, 06:15:06 pm »
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  :popcorn:
Should you find yourself in a chronically leaking boat, energy devoted to changing vessels is likely to be more productive than energy devoted to patching leaks.

Warren Buffett
 

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1198
  • Country: fi
Re: Raspberry Pi Or Arduino
« Reply #1 on: October 03, 2018, 06:28:29 pm »
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)?

Offline donotdespisethesnake

  • Super Contributor
  • ***
  • Posts: 1093
  • Country: gb
  • Embedded stuff
Re: Raspberry Pi Or Arduino
« Reply #2 on: October 03, 2018, 07:15:13 pm »
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

Not sure what an 8-bit port is, are these discrete IOs?

Quote
and outputting to a text based VFD display after some calculation.

What is the display interface? SPI, I2C, Ethernet??

What calculations? How fast?

Quote
The CPU board needs to be 32-bit as I will be handling some large numbers

Even 8 bit Arduinos can handle 64 bit values...depends on many Flops you need.
 
Quote
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.
USB host or device? What device class?

Quote
So, Arduino or Raspberry Pi, and please explain your answer  :popcorn:

Insufficient data...but sounds like it can be done with an Arduino.
Bob
"All you said is just a bunch of opinions."
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Raspberry Pi Or Arduino
« Reply #3 on: October 03, 2018, 07:31:38 pm »
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.
 

Offline jpb

  • Super Contributor
  • ***
  • Posts: 1771
  • Country: gb
Re: Raspberry Pi Or Arduino
« Reply #4 on: October 03, 2018, 07:47:45 pm »
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.
 

Offline German_EETopic starter

  • Super Contributor
  • ***
  • Posts: 2399
  • Country: de
Re: Raspberry Pi Or Arduino
« Reply #5 on: October 03, 2018, 08:16:10 pm »
OK, an idea of the task

1) Input 4 x 8 bits using an 8-bit port and some chip select lines. All signals at CMOS (74HC) levels

2) Assemble these into a single 32-bit word

3) Work out ((2^32) / input word) + stored offset), integer maths will be fine here

4) Output the result to the display using either an SPI or I2C interface

5) If required by an external command output the displayed number through the USB port to the PC

I'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.
Should you find yourself in a chronically leaking boat, energy devoted to changing vessels is likely to be more productive than energy devoted to patching leaks.

Warren Buffett
 

Offline HB9EVI

  • Frequent Contributor
  • **
  • Posts: 722
  • Country: ch
Re: Raspberry Pi Or Arduino
« Reply #6 on: October 03, 2018, 08:31:07 pm »
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 Pi

Pi is nice and fun for experimenting though
 

Online TK

  • Super Contributor
  • ***
  • Posts: 1722
  • Country: us
  • I am a Systems Analyst who plays with Electronics
Re: Raspberry Pi Or Arduino
« Reply #7 on: October 03, 2018, 08:38:03 pm »
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.
 

Offline nfmax

  • Super Contributor
  • ***
  • Posts: 1560
  • Country: gb
Re: Raspberry Pi Or Arduino
« Reply #8 on: October 03, 2018, 09:29:07 pm »
Raspberry Pi GPIO's are 3.3V only, so you may be better off with an Arduino just for that reason.
 

Offline donotdespisethesnake

  • Super Contributor
  • ***
  • Posts: 1093
  • Country: gb
  • Embedded stuff
Re: Raspberry Pi Or Arduino
« Reply #9 on: October 03, 2018, 09:31:55 pm »
5) If required by an external command output the displayed number through the USB port to the PC

I 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.

Quote
I'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.

I 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++.

Bob
"All you said is just a bunch of opinions."
 

Offline NivagSwerdna

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: Raspberry Pi Or Arduino
« Reply #10 on: October 03, 2018, 09:54:50 pm »
So, Arduino or Raspberry Pi, and please explain your answer  :popcorn:
Depends on power requirements.  If Battery Powered... Arduino or ESP32... if powered from a mains supply... Pi.
 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 4036
  • Country: nz
Re: Raspberry Pi Or Arduino
« Reply #11 on: October 03, 2018, 09:55:00 pm »
OK, an idea of the task

1) Input 4 x 8 bits using an 8-bit port and some chip select lines. All signals at CMOS (74HC) levels

2) Assemble these into a single 32-bit word

3) Work out ((2^32) / input word) + stored offset), integer maths will be fine here

4) Output the result to the display using either an SPI or I2C interface

5) If required by an external command output the displayed number through the USB port to the PC

I'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.

Ten 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.
 

Offline cv007

  • Frequent Contributor
  • **
  • Posts: 826
Re: Raspberry Pi Or Arduino
« Reply #12 on: October 03, 2018, 10:56:09 pm »
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.
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3360
  • Country: nl
Re: Raspberry Pi Or Arduino
« Reply #13 on: October 04, 2018, 12:45:49 am »
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.
 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 4036
  • Country: nz
Re: Raspberry Pi Or Arduino
« Reply #14 on: October 04, 2018, 01:00:07 am »
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: [Select]
unsigned long calc(unsigned long input_word){
  unsigned long result = 0xfffffffful/input_word;
  if ((input_word & (input_word - 1)) == 0) ++result;
  return result;
}
[code]

 
The following users thanked this post: Ian.M

Offline kaevee

  • Regular Contributor
  • *
  • Posts: 110
  • Country: in
Re: Raspberry Pi Or Arduino
« Reply #15 on: October 04, 2018, 01:14:15 am »
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  :popcorn:

You 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 debugging
  • 40-pin LaunchPad kit standard leveraging the BoosterPack ecosystem
  • On-board eZ-FET debug probe
  • 2 buttons and 2 LEDs for user interaction
  • On-board micro SD Card
  • Super Capacitor (0.22 F)
TI Claims

The 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.
 

Offline rjp

  • Regular Contributor
  • *
  • Posts: 124
  • Country: au
Re: Raspberry Pi Or Arduino
« Reply #16 on: October 04, 2018, 01:15:10 am »
a 555 timer should handle this fine.
 

Offline German_EETopic starter

  • Super Contributor
  • ***
  • Posts: 2399
  • Country: de
Re: Raspberry Pi Or Arduino
« Reply #17 on: October 04, 2018, 03:13:53 pm »
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 it  :)  Fortunately 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.
Should you find yourself in a chronically leaking boat, energy devoted to changing vessels is likely to be more productive than energy devoted to patching leaks.

Warren Buffett
 

Offline donotdespisethesnake

  • Super Contributor
  • ***
  • Posts: 1093
  • Country: gb
  • Embedded stuff
Re: Raspberry Pi Or Arduino
« Reply #18 on: October 04, 2018, 09:35:03 pm »
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.

An 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.
Bob
"All you said is just a bunch of opinions."
 

Offline Dielectric

  • Regular Contributor
  • *
  • Posts: 127
  • Country: 00
Re: Raspberry Pi Or Arduino
« Reply #19 on: October 05, 2018, 01:08:40 pm »
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.
 

Offline GeorgeOfTheJungle

  • Super Contributor
  • ***
  • !
  • Posts: 2699
  • Country: tr
Re: Raspberry Pi Or Arduino
« Reply #20 on: October 05, 2018, 01:24:13 pm »
OK, an idea of the task

1) Input 4 x 8 bits using an 8-bit port and some chip select lines. All signals at CMOS (74HC) levels

2) Assemble these into a single 32-bit word

3) Work out ((2^32) / input word) + stored offset), integer maths will be fine here

4) Output the result to the display using either an SPI or I2C interface

An arduino uno can do all that just fine, me thinks.

5) If required by an external command output the displayed number through the USB port to the PC

The PC will see it as a serial port.

A Raspberry Pi takes ages to boot, compared to an arduino.
« Last Edit: October 05, 2018, 01:26:22 pm by GeorgeOfTheJungle »
The further a society drifts from truth, the more it will hate those who speak it.
 

Offline Fungus

  • Super Contributor
  • ***
  • Posts: 16664
  • Country: 00
Re: Raspberry Pi Or Arduino
« Reply #21 on: October 05, 2018, 01:34:07 pm »
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  :popcorn:

Arduino can handle 32-bit numbers, will be a lot simpler learning curve, will boot very quickly (no need to load an entire graphical OS).

I guess it all depends on what "large numbers" are.  :popcorn:

 

Offline German_EETopic starter

  • Super Contributor
  • ***
  • Posts: 2399
  • Country: de
Re: Raspberry Pi Or Arduino
« Reply #22 on: October 05, 2018, 07:44:54 pm »
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.
Should you find yourself in a chronically leaking boat, energy devoted to changing vessels is likely to be more productive than energy devoted to patching leaks.

Warren Buffett
 

Offline taydin

  • Frequent Contributor
  • **
  • Posts: 520
  • Country: tr
Re: Raspberry Pi Or Arduino
« Reply #23 on: October 05, 2018, 08:02:25 pm »
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.
Real programmers use machine code!

My hobby projects http://mekatronik.org/forum
 

Offline donotdespisethesnake

  • Super Contributor
  • ***
  • Posts: 1093
  • Country: gb
  • Embedded stuff
Re: Raspberry Pi Or Arduino
« Reply #24 on: October 05, 2018, 09:34:57 pm »
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.

Hmm, 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.

Bob
"All you said is just a bunch of opinions."
 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 4036
  • Country: nz
Re: Raspberry Pi Or Arduino
« Reply #25 on: October 05, 2018, 11:58:35 pm »
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!

Technically 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: [Select]
add A,a
adc B,b
adc C,c
adc D,d

Four 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: [Select]
clc
lda A
adc a
sta A
lda B
adc b
sta B
lda C
adc c
sta C
lda D
adc d
sta D

Thirteen 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).
 
The following users thanked this post: GeorgeOfTheJungle

Offline martinjaymckee

  • Contributor
  • Posts: 16
Re: Raspberry Pi Or Arduino
« Reply #26 on: October 06, 2018, 06:42:31 am »
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
 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 4036
  • Country: nz
Re: Raspberry Pi Or Arduino
« Reply #27 on: October 06, 2018, 08:46:15 am »
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.

It'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.

Quote
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....

What 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).

Quote
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.

Yes, it's a shame. It's really not that hard to convert the standard...

Code: [Select]
void setup() {
    pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {

    digitalWrite(LED_BUILTIN, HIGH);
    delay(1000);
    digitalWrite(LED_BUILTIN, LOW);
    delay(1000);
}

... to ...

Code: [Select]
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,.
 
 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 4036
  • Country: nz
Re: Raspberry Pi Or Arduino
« Reply #28 on: October 06, 2018, 08:53:08 am »
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.

If 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/hifive1

https://www.digikey.com/products/en?keywords=hifive1

https://nz.mouser.com/ProductDetail/Crowd-Supply/cs-hifive1-01?qs=%2fha2pyFaduiYWq09B7sm7wDmAaLBQ5QCD7BSHMmGALI%3d

 

Offline donotdespisethesnake

  • Super Contributor
  • ***
  • Posts: 1093
  • Country: gb
  • Embedded stuff
Re: Raspberry Pi Or Arduino
« Reply #29 on: October 06, 2018, 09:31:03 am »
It has 6x less SRAM than the Due (16 kB)

That's a total waste of time then! But thanks for the spam.
Bob
"All you said is just a bunch of opinions."
 

Offline GeorgeOfTheJungle

  • Super Contributor
  • ***
  • !
  • Posts: 2699
  • Country: tr
Re: Raspberry Pi Or Arduino
« Reply #30 on: October 06, 2018, 09:40:47 am »
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.
If 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).

The ARM "bluepill" arduino is hard to beat at ~ $2:

http://wiki.stm32duino.com/index.php?title=Blue_Pill
http://wiki.stm32duino.com/index.php?title=Installation
https://robotdyn.com/stm32f103-stm32-arm-mini-system-dev-board-stm-firmware.html

Quote
The F103C8 ST microcontroller is declared to have 64 KB of flash, but virtually all the C8 microcontrollers tested have 128 KB of flash instead
« Last Edit: October 06, 2018, 09:44:35 am by GeorgeOfTheJungle »
The further a society drifts from truth, the more it will hate those who speak it.
 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 4036
  • Country: nz
Re: Raspberry Pi Or Arduino
« Reply #31 on: October 06, 2018, 10:06:56 am »
It has 6x less SRAM than the Due (16 kB)

That's a total waste of time then! But thanks for the spam.

Still 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.
 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 4036
  • Country: nz
Re: Raspberry Pi Or Arduino
« Reply #32 on: October 06, 2018, 10:09:40 am »
Certainly that's very nice for $2 or $3.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf