Go Down

Topic: Raspberry Pi - first experance (Read 7878 times) previous topic - next topic

Grumpy_Mike

Well I have had my Pi for just about two weeks and I have very mixed feelings about it. It is not much good for doing stuff where you need a times access to the input or output pins. Like it is totally useless for sampling an audio signal from an A/D as the interrupts can steal up to 10mS of time off you at random. Then and again you can probably get a plug in USB microphone and drivers to use it.
Anyway I have just made a simple buffer board and put the write up on line along with a simple little video.
http://www.thebox.myzen.co.uk/Raspberry/Buffer_Board.html

The code to flash a few LEDs is much more complex than an Arduino, this is what I used for that project:-
Code: [Select]

//  LED light chase by Mike Cook June 2012
//
//  Based on:-
//  How to access GPIO registers from C-code on the Raspberry-Pi
//  Example program
//  15-January-2012
//  Dom and Gert
//  


// Access from ARM Running Linux

#define BCM2708_PERI_BASE        0x20000000
#define GPIO_BASE                (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dirent.h>
#include <fcntl.h>
#include <assert.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>

#include <unistd.h>

#define PAGE_SIZE (4*1024)
#define BLOCK_SIZE (4*1024)

int  mem_fd;
char *gpio_mem, *gpio_map;
char *spi0_mem, *spi0_map;

// normal order of output pins
//char pins[] = { 1, 4, 7, 8, 9, 10, 11, 17, 18, 21, 22, 23, 24, 25 };

// order of output pins to make a chase sequence
 char pins[] = { 4, 8, 10, 17, 21, 23, 25, 24, 22, 18, 11, 9, 7, 1 };

// I/O access
volatile unsigned *gpio;


// GPIO setup macros. Always use INP_GPIO(x) before using OUT_GPIO(x) or SET_GPIO_ALT(x,y)
#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
#define OUT_GPIO(g) *(gpio+((g)/10)) |=  (1<<(((g)%10)*3))
#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))

#define GPIO_SET *(gpio+7)  // sets   bits which are 1 ignores bits which are 0
#define GPIO_CLR *(gpio+10) // clears bits which are 1 ignores bits which are 0

void setup_io();
void delay(int del);

int main(int argc, char **argv)
{ int g,rep;

 // Set up gpi pointer for direct register access
 setup_io();

 // Switch GPIO 7..11 to output mode

/************************************************************************\
 * You are about to change the GPIO settings of your computer.          *
 * Mess this up and it will stop working!                               *
 * It might be a good idea to 'sync' before running this program        *
 * so at least you still have your code changes written to the SD-card! *
\************************************************************************/

 // Set all exposed GPIO pins to output
 for (g=0; g<=32; g++)
 {
   if( ((1<<g) & 0x3e6cf93) != 0){
   INP_GPIO(g); // must use INP_GPIO before we can use OUT_GPIO
   OUT_GPIO(g);
  }
 }
GPIO_CLR = 0x3e6cf93; // clear all output pins

for(; ;){
 for (rep=0; rep<14; rep++)
    { GPIO_SET = 1<<pins[rep];
     delay(50); }  
  for (rep=0; rep<14; rep++)
    { GPIO_CLR = 1<<pins[rep];
     delay(50); }

}
 return 0;

} // main

void delay(int del){
int i, j, dum;
 for(i=0; i<del; i++){
    for(j=0; j<0x1180; j++){
     dum = INP_GPIO(0); // dummy read to stop compiler optimising this away
    }
  }
}

//
// Set up a memory regions to access GPIO
//
void setup_io()
{

  /* open /dev/mem */
  if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) {
     printf("can't open /dev/mem \n");
     exit (-1);
  }

  /* mmap GPIO */

  // Allocate MAP block
  if ((gpio_mem = malloc(BLOCK_SIZE + (PAGE_SIZE-1))) == NULL) {
     printf("allocation error \n");
     exit (-1);
  }

  // Make sure pointer is on 4K boundary
  if ((unsigned long)gpio_mem % PAGE_SIZE)
    gpio_mem += PAGE_SIZE - ((unsigned long)gpio_mem % PAGE_SIZE);

  // Now map it
 // gpio_map = (unsigned char *)mmap(
  gpio_map = ( char *)mmap(
     (caddr_t)gpio_mem,
     BLOCK_SIZE,
     PROT_READ|PROT_WRITE,
     MAP_SHARED|MAP_FIXED,
     mem_fd,
     GPIO_BASE
  );

  if ((long)gpio_map < 0) {
     printf("mmap error %d\n", (int)gpio_map);
     exit (-1);
  }

  // Always use volatile pointer!
  gpio = (volatile unsigned *)gpio_map;


} // setup_io


Just the video is here:-


https://vimeo.com/43337992

Jantje

Grumpy
Thanks for sharing your experiences.

Your experiences confirm my thinking.
Do not do real time stuff on the PI. Do real time stuff on Arduino. For more advanced projects Arduino and the PI can be a perfect match. Use the Arduino for the real time stuff and move all "non real time" stuff to the PI.
I say "non real time" because I mean all things hard to do real time in Arduino. I currently think of network (hard to predict), security algorithms and logging on sd card (again hard to predict).
As shown in another thread the serial port is perfect for this.
Best regards.
Jantje
Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

focalist

This is why I believe the search for an "Arduino Killer" simply will never be fruitful.  (hehe)

Arduino and Microchip's PIC and the others fill a niche that others cannot-  a cheap, simple, user-buildable device that you don't mind setting on fire by mistake.

Through hole DIP- that's what hobbyists want.  The 644 and 1280(?) provide 40 pins.. but in all honesty, how often have you actually "run out" of I/O on a 328, unless it's for an LED matrix?  In that case, you ought to be using shift registers probably anyway.

I'm actually trending in the opposite direction for some of my builds, I am planning on picking up a few ATMEGA8's and ATTINY's and giving them a whirl for projects that don't really require a 328.  Of course, I may just get 168's instead, they are getting DIRT cheap.

I've got an ST32F4 Discovery, and got so sick of trying to load their IDE, it's on a shelf collecting dust.  Same with the TI Launchpad.

Long live Arduino.. cuz these larger boards aren't as user friendly and cheap in the end.. and their user base just isn't...Arduino.

Osgeld

Quote
The 644 and 1280(?) provide 40 pins.. but in all honesty, how often have you actually "run out" of I/O on a 328


1284, and I never run out of pins, I run out of ram which is why I keep them around, though I do goofy crap like video projects that suck a ton of space for a buffer. AS far as the PI goes its not in the same area as an arduino, I think of it as a small computer, just like my other small computers which brings up ...

Quote
Do not do real time stuff on the PI. Do real time stuff on Arduino.


I think you mean physical stuff, I am sure the PI could kick the living sh.t out of an arduino at realtime game of team fortress, but much like using your printer port to read a button its probably easier to plug in a little USB do-hicky like the arduino to do it for you, especially if timing is critical.

http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

Grumpy_Mike

Quote
AS far as the PI goes its not in the same area as an arduino, I think of it as a small computer

Yes I quite agree.

What the Pi is good for is those projects that you would normally do with and arduino talking to Processing.

Like the art ones that are always coming up, "I want to output a sound as some one approaches my work" or "I want to show a video clip that depends on what object someone has picked up".

Jantje


Quote

Quote
Do not do real time stuff on the PI. Do real time stuff on Arduino.


I think you mean physical stuff,

I can not make any statements on doing physical stuff on the PI. I'm not a hardware guy.
So; I mean real time. Like described in http://en.wikipedia.org/wiki/Real-time_computing
The statement of Grumpy below shows that PI is not your best choice to do real time computing.
Quote
Like it is totally useless for sampling an audio signal from an A/D as the interrupts can steal up to 10mS of time off you at random.

The simple reason is that "to much is going on" on a multi threaded system. These threads may eat time at times you don't want to. The time eating can vary over time (like http requests) and make the system sometimes miss information.
Add to that the little resources the PI has and you understand that on a PI you are bound to miss an audio samples or input triggers while someone is visiting your webs site.
All these problems are (nearly) non existing on a single threaded Arduino dedicated to a set of tasks where the time constraints are well known and controllable.

Best regards
Jantje

Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Grumpy_Mike

Yes I know why it misses time, I just was not expecting it to miss so much time. This is a lot more than other ARM systems I have used, like the RISC PC.

UnaClocker

Maybe it'll be better with an RTOS Linux on it?

Chagrin

I've never used the RT patches, but I'm sure an immediate improvement could be gained just by turning off X Windows.

terryking228

RaspBerry Pi  3 New 3 Month Delay??

I was supposed to get my Pi in early June. Today I got this news:
---------------------( COPY )--------------------------
Unfortunately, due to unforeseen circumstances causing a delay in the supply chain, we can't send your order just yet, but it will be despatched the week commencing 09/07/2012. You will receive a confirmation email prior to your Raspberry Pi being shipped.
-----------------( END COPY )----------------------
Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

Nishant_Sood

There is no comparison between the Arduino Almighty and these Linux running Big Buns and that you folks also understand with all that experience you have.

With this post im getting to think that Beagle Bone is a better thing as i have seen it working but haven't heard of the similar stuff with that, Nevermind.
"Real Men can Accomplish  Anything"

- skype : nishants5  
ਫ਼ਤੇਹ ਕਰੁਂ!
www.winacro.com

simon.monk

I agree wholeheartedly with the Pi not being an Arduino competitor.

I have a blog entry flashing an LED using Python as an alternative to C - http://www.doctormonk.com/2012/05/gpio-led-blink-from-python-using-slice.html

and also on using the Pi to talk to an Arduino through USB, again using Python - http://www.doctormonk.com/2012/04/raspberry-pi-and-arduino.html

--
I write books about Arduino and Electronics: http://simonmonk.org

Grumpy_Mike

I did this video this week, hitching it up to my Glock.
https://vimeo.com/44300050

It runs fine, but if I so much as move the mouse it all slows down, and if I drag a window at the same time the notes are few and far between.
What is needed is a delay function that is based on a hardware clock not just a software loop, but I haven't had time to look into that yet.

They made a bit of a mess of labeling the expansion header, so I spent some time editing the wiki entry.
http://elinux.org/RPi_Low-level_peripherals

UnaClocker


RaspBerry Pi  3 New 3 Month Delay??

I was supposed to get my Pi in early June. Today I got this news:
---------------------( COPY )--------------------------
Unfortunately, due to unforeseen circumstances causing a delay in the supply chain, we can't send your order just yet, but it will be despatched the week commencing 09/07/2012. You will receive a confirmation email prior to your Raspberry Pi being shipped.
-----------------( END COPY )----------------------


Ouch! Which vendor did that to you? Allied is the only one still holding out on me. I got 2 from RS and 2 from Newark already. I had originally expected to be able to buy about 1 a month, I suppose if I staggered my orders out better, it'd work out that way. Really strange that they can't fill the orders that were placed months ago.

AWOL

#14
Jun 22, 2012, 08:41 am Last Edit: Jun 22, 2012, 08:43 am by AWOL Reason: 1
About a week and a half ago, I had a notification email from ParcelFarce to say that RS had shipped mine and gave me a tracking reference, but no package tracking details were available.
I contacted RS earlier this week to ask what was going on and they replied that due to "difficulties" the shipment hadn't been made, but yesterday I got another ParcelFarce notification email, but again, no tracking details are available for the (different) reference number.

I am hugely under-impressed.

The BeagleBone was relatively expensive, but at least it turned up on time.

Go Up