iamwill
Posts: 6
Joined: Tue Jan 19, 2016 3:00 am

[SOLVED] Programming Pi

Tue Jan 19, 2016 3:02 am

This might be a dumb question, bit do I need to install an OS on the pi or can I program it like an arduino without an OS installed?
Last edited by iamwill on Tue Jan 19, 2016 6:00 am, edited 1 time in total.

User avatar
mikronauts
Posts: 2779
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: Programming Pi

Tue Jan 19, 2016 3:21 am

Yes, you need to install an OS

No, you cannot program it like an Arduino
iamwill wrote:This might be a dumb question, bit do I need to install an OS on the pi or can I program it like an arduino without an OS installed?
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

User avatar
Douglas6
Posts: 4853
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Programming Pi

Tue Jan 19, 2016 3:27 am

Well, there is 'bare-metal' programming with no OS (there's a forum here), but it's a far cry from Arduino coding.

User avatar
mikronauts
Posts: 2779
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: Programming Pi

Tue Jan 19, 2016 3:29 am

there is also Win10IoT for the Rpi2, with Visual Studio... but I would not really call that Arduino like either.

Frankly one of the main attractions of Pi's is self-hosted development, and the Pi's capabilities are significantly different from an Arduino, so it does not make sense to me to try to turn a Pi into an Arduino.

Perhaps the OP should just use WiringPi, and rdp into a Pi...
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

User avatar
kolban
Posts: 143
Joined: Fri Dec 04, 2015 1:45 am
Location: Texas, USA

Re: Programming Pi

Tue Jan 19, 2016 3:47 am

There actually is an early life project that allows one to use the Arduino IDE editor and run existing Arduino sketches on a Pi ... see:

https://github.com/me-no-dev/RasPiArduino
FREE book on Raspberry Pi usage and programming

https://leanpub.com/pi

User avatar
dobra-dobra
Posts: 34
Joined: Wed Dec 26, 2012 2:04 pm
Location: Poland

Re: Programming Pi

Tue Jan 19, 2016 3:54 am

kolban wrote:There actually is an early life project that allows one to use the Arduino IDE editor and run existing Arduino sketches on a Pi ... see:

https://github.com/me-no-dev/RasPiArduino
Wow! That is really cool! Thank your for the tip. It seems that it's quite active project, too. Good find. I need to try it.

User avatar
Douglas6
Posts: 4853
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Programming Pi

Tue Jan 19, 2016 4:05 am

kolban wrote:There actually is an early life project that allows one to use the Arduino IDE editor
Yes, but that runs on top of Raspbian, Pi's Linux OS.

pxgator
Posts: 105
Joined: Mon Feb 16, 2015 6:45 pm
Location: Southern Colorado, USA

Re: Programming Pi

Tue Jan 19, 2016 4:06 am

Unless you are an expert in assembly and C programming you do need an OS for the pi.
The pi has much more to offer than an arduino. Especially the RPi 2. By using wiringpi and
or the pigpio libraries and a RPi 2 you can do hardware io processing to within a few microseconds.
Plus the fact that you get a visual multitasking environment to work with puts the pi miles
ahead of an arduino. If you are stuck on arduino style coding there is some software that runs
very well on the RPi 2 and it is what the arduino environment is based on.
https://www.raspberrypi.org/blog/now-av ... rocessing/
So what's all this RPi stuff anyhow? Well folks, it's a feat of engineering from
the UK almost as remarkable as the De Havilland Mosquito and the Colossus.

User avatar
kolban
Posts: 143
Joined: Fri Dec 04, 2015 1:45 am
Location: Texas, USA

Re: Programming Pi

Tue Jan 19, 2016 4:19 am

What got me thinking about using the Pi in the same fashion as an Arduino are the following thoughts:

1) I find that there is a wealth of pre-written sketches for Arduino interfacing with components, modules and other electronic parts. If what I want to do is get my part "operational" as quickly as possible ... even if just for sniff testing ... I may be able to achieve that quicker getting an existing Arduino sketch and running it on the Pi.

2) If I am developing an Arduino application that is destined to run on the Arduino, I can use the Pi as my development environment. Obviously this can produce different results than running on a real Arduino but ... so far ... my personal experience is that they are so close to being the same I haven't found a problem with any programs Ive written. I also get to "drop down" to using debuggers such as "gdb" and "ddd" to step through my "sketch" code which is now nothing more than a Pi executable.

3) The biggest part of this open source project is the development of the Arduino APIs ported to Raspbian and interacting with the BCM peripheral controller. From what I understand, the GPIO, SPI, I2C, UART (etc) interfacing in this project is built from the ground up ... i.e. it doesn't pre-req any existing GPIO libraries such as wiringpi or pigpio ... it is yet another implementation. What this means (to me) ... is that I can write Raspbian C/C++ code natively on the Pi and the API I use for interfacing with the hardware can be the Arduino APIs. This means that if I become familiar with one set of API (for example SPI class) for Arduino then those skills translate straight over into Pi programming but yet, I don't seem to have lost any "qualities" by using that API as opposed to an alternate API which I am assuming does exactly the same things.
FREE book on Raspberry Pi usage and programming

https://leanpub.com/pi

iamwill
Posts: 6
Joined: Tue Jan 19, 2016 3:00 am

Re: Programming Pi

Tue Jan 19, 2016 4:46 am

My concern is; installing raspbian and running Linux... Can it withstand the power hits or does it need to be shut down properly? I want to build a box with 5 pi's that will take 5 different USB inputs (one from each pi) and transfer files from USB to a raid server via cat5. I don't want to worry about Linux crashing because of repeated power cycles. Just a concern but maybe not valid if raspbian is specialized in losing power instantly.

User avatar
Douglas6
Posts: 4853
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Programming Pi

Tue Jan 19, 2016 5:04 am

iamwill wrote:Just a concern but maybe not valid if raspbian is specialized in losing power instantly.
It's not. Like any OS, you take the chance of file corruption if you remove power before shutting down. There are ways to reduce risk (read-only file systems), but most folks just keep it plugged in. Or rig a UPS if mains power is flakey.

W. H. Heydt
Posts: 12431
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Programming Pi

Tue Jan 19, 2016 5:12 am

iamwill wrote:My concern is; installing raspbian and running Linux... Can it withstand the power hits or does it need to be shut down properly? I want to build a box with 5 pi's that will take 5 different USB inputs (one from each pi) and transfer files from USB to a raid server via cat5. I don't want to worry about Linux crashing because of repeated power cycles. Just a concern but maybe not valid if raspbian is specialized in losing power instantly.
It depends on factors that haven't been discussed yet. The thing to watch out for is that SD cards do wear leveling internally and if you drop the power when that is taking place, you may corrupt the card. On top of that, Linux--like unix before it--doesn't write out "disk" blocks until it needs to, so there will be "dirty" pages in memory. If the power drops, Linux will be unable to write those pages and--again--you may get a corrupted file system. You really, really want to do a proper shutdown. If you can't do a proper shut down, and you can't allow the system to go "quiet" for at least 30 seconds before the power cut, you need to have your writeable file system somewhere other than on an SD card, and even then you should try to get a sync command in and complete before the power is pulled.

If your Pis are going to be where the power is unstable, you should consider some form of UPS for your Pis. One option is this one: http://www.allspectrum.com/mopower/ It comes as a kit. I'm about to start evaluation testing on one that was put together by a friend of mine (some of the surface mount components are pretty small, and my eyes are none too good any more). Another alternative would be a full, commercial UPS to power all five Pis off one unit.

User avatar
Greg Erskine
Posts: 140
Joined: Sat Sep 15, 2012 4:20 am

Re: Programming Pi

Tue Jan 19, 2016 5:15 am

iamwill wrote:My concern is; installing raspbian and running Linux... Can it withstand the power hits or does it need to be shut down properly? I want to build a box with 5 pi's that will take 5 different USB inputs (one from each pi) and transfer files from USB to a raid server via cat5. I don't want to worry about Linux crashing because of repeated power cycles. Just a concern but maybe not valid if raspbian is specialized in losing power instantly.
piCore is a version of Tiny Core Linux for the Raspberry Pi that runs in RAM. Pull the plug whenever you like!
* Raspberry Pi is a trademark of the Raspberry Pi Foundation

Heater
Posts: 15838
Joined: Tue Jul 17, 2012 3:02 pm

Re: Programming Pi

Tue Jan 19, 2016 5:27 am

Just make sure your root file system is mounted read only. Then your SD is not going to get corrupted. Here are some instructions, hint's and tips on read only root: https://wiki.debian.org/ReadonlyRoot

As you are intending to store your data externally to the Pi's this should work fine for you.

I would worry about the RAID box. RAID may well make for more robust storage but it can still fail with catastrophic data loss. Is that all going to be backed up somewhere else?
Memory in C++ is a leaky abstraction .

iamwill
Posts: 6
Joined: Tue Jan 19, 2016 3:00 am

Re: Programming Pi

Tue Jan 19, 2016 5:34 am

The raid isn't going to be connected to any of the rpi's per-se.. the pi will just grab the file from the usb device, once it has the whole file, it will transfer it to the raid through a switch via ethernet. the raid server will be a whole other setup on UPS... an actual computer/server.

Thanks for the help. I will try piCore.

fruitoftheloom
Posts: 23132
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: Programming Pi

Tue Jan 19, 2016 5:35 am

iamwill wrote:This might be a dumb question, bit do I need to install an OS on the pi or can I program it like an arduino without an OS installed?
The Raspberry Pi has no BIOS so you need a SD Cardwith a Boot Pertition:

http://wiki.beyondlogic.org/index.php?t ... ot_Process

Therefore once it has completed the 3rd Stage you have an OS Kernel loaded...............

http://www.webopedia.com/TERM/K/kernel.html
Rather than negativity think outside the box !
RPi 4B 4GB (SSD Boot)..
Asus ChromeBox 3 Celeron is my other computer...

W. H. Heydt
Posts: 12431
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Programming Pi

Tue Jan 19, 2016 5:41 am

iamwill wrote:he raid server will be a whole other setup on UPS... an actual computer/server.
Humph. A Pi *is* an "actual computer".

iamwill
Posts: 6
Joined: Tue Jan 19, 2016 3:00 am

Re: Programming Pi

Tue Jan 19, 2016 6:00 am

I knew that would comment would spark a comment! :). How about a "traditional" computer. We all understand that the pi is a computer....

Thanks again everyone for helping. It was appreciated.

W. H. Heydt
Posts: 12431
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Programming Pi

Tue Jan 19, 2016 6:29 am

iamwill wrote:I knew that would comment would spark a comment! :). How about a "traditional" computer. We all understand that the pi is a computer....

Thanks again everyone for helping. It was appreciated.
Oh...*traditional*. Yeah, it's a traditional computer. All the parts are there.

Bear in mind that the first machine I was paid to program on was an IBM S/360-30 with 32K bytes of memory, 4 IBM 2311 disk drives (removable pack, 7.25MB per pack) and an OS with a nucleus that took 6K and could run one user task at a time, the Pi is a pretty impressive computer. One could easily simulate that S/360 on...and have it run far, far faster than the original. About the only thing that S/360 could do better would be related to the difficulty of connecting an 1100 lpm impact printer to the Pi.

User avatar
Douglas6
Posts: 4853
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: [SOLVED] Programming Pi

Tue Jan 19, 2016 6:39 am

Ah, I recall the 'traditional' S/360. Took a (large) room in my high school. Can put it in my pocket now. Kids have it easy.

Return to “General discussion”