What programming language to use for programming pi

Discussion in 'Programmer's Corner' started by fan1, Jun 11, 2016.

  1. fan1

    Thread Starter New Member

    Jun 11, 2016
    5
    0
    I am thinking of programming water pump with raspberry pi , so my question is what programming language should I use. I searched online and found i should use C or pyton. We did C in school so I know basic stuff and a little bit more(was working in code blocks). Python is completely secret for me. So what you guys suggest? All i need to program is a simple on/off loop with a timer.
     
  2. tindel

    Active Member

    Sep 16, 2012
    568
    193
    I wouldn't waste the space or horsepower of a pi to run a pump timer. I'd use a micro with a 32kHz crystal. This will limit you to C or asm. I'd suggest C because it's pretty much universally used in embedded systems. Check out the MSP430 launchpad series. I'd suggest this one because it will hold data in FRAM even thru a power cycle, has a super cap to keep the RTC time correct when unplugged (assuming you've optimized for low power), and has a 32kHz crystal on board. Everything you need for a good timer application.
     
  3. hellifino

    New Member

    Jul 2, 2015
    19
    1
    Just grab an Arduino nano off Amazon for a few bucks. You'll prolly need to pick up a FTDI converter too (uses a MINI usb cable)... Install Arduino IDE - it's all C. You'll also need to build a driver circuit for your pump since that's going to pull more current than an Arduino can source (You can also buy these off Amazon - search "motor driver shield" etc).
     
  4. mcgyvr

    AAC Fanatic!

    Oct 15, 2009
    4,771
    971
    I've been having fun with ESP8266 micros lately.. Super simple/cheap to connect to wifi and get the time from a time server then perform functions off that..
    It can be programmed via C or using the Arduino IDE (Arduino/wiring language)
     
  5. GopherT

    AAC Fanatic!

    Nov 23, 2012
    6,071
    3,842
    Can you share a simple program for your ESP8266 using the arduino IDE? I'm not having much luck using the arduino IDE.
     
  6. mcgyvr

    AAC Fanatic!

    Oct 15, 2009
    4,771
    971
  7. GopherT

    AAC Fanatic!

    Nov 23, 2012
    6,071
    3,842
  8. mcgyvr

    AAC Fanatic!

    Oct 15, 2009
    4,771
    971
    It works with all ESP8266 boards (probably).. I know it works with just the cheapo $1.99 "base" ESP8266 modules that you need the FTDI board/regulators,etc.. to program..

    I've just been using the huzzah but I'm fairly sure you need to put the ESP8266 barebones chips into "bootloader" (pull some pins high/low) mode too so they can be programmed..
     
    GopherT likes this.
  9. vpoko

    Member

    Jan 5, 2012
    258
    47
    If you decide to use a Pi (which I agree is extreme overkill for what you're doing), you can use any language you like. There are memory locations that you can write to/read from that correspond to the GPIO pins, and since the Pi gives you a full Linux environment (or in theory other OS's, though Linux is what people use), you can use any language supported on that platform. C, C++, Python, Java, C# (Mono), etc. You can also create simple drivers for the GPIO in one language and use the driver from another.
     
  10. fan1

    Thread Starter New Member

    Jun 11, 2016
    5
    0
    Thanks guys for all the help. I didn't realise pi might be an overkill. I might grab something else. Can you tell me what would be best use for pi.
     
  11. GopherT

    AAC Fanatic!

    Nov 23, 2012
    6,071
    3,842
    Overkill or not, if you have a pi and you have one value-added project idea, use the pi.
     
  12. vpoko

    Member

    Jan 5, 2012
    258
    47
    Anything where you'd benefit from having a full OS and relatively strong hardware (1.2 GHz CPU and 1 GB RAM on the Raspberry Pi 3). Applications that use TCP/IP networking, need a filesystem, need the ability to play/record/transcode audio or video, need to process large amounts of data, want to present a full GUI, or where you'd benefit from multitasking might be some examples, but of course there are countless other uses for it. I suppose I think of it more like a little PC (that can be put into a solution if need be) than an actual piece of embedded electronics like an Atmel AVR chip. It's not that it's wrong for your application, but I guess it gives people some kind of uneasy feeling to use an over-engineered solution when a lower-cost, lower-power one would work just as well. At $35 for the Raspberry Pi, the feeling might not be all that justified, and it's a pretty cool piece of hardware to have and learn to use. And if you already have it, there's definitely sense in using it (though it might feel underappreciated controlling a pump when it's capable of so much more).
     
  13. MPep

    New Member

    Dec 24, 2014
    1
    0
    Just a suggestion but for a simple programmable timer loop, check out PICAXE. All programming is done using BASIC. Easily readable and they have their own friendly forum.
     
  14. odm4286

    Active Member

    Sep 20, 2009
    155
    5
    Here's my two cents about Python vs C. Learn C, Python might be "easier" but it'll hold your hand too much. I also believe Python will teach you some bad habits. I don't like how Python handles datatypes, there aren't any, and the fact that it depends on indentation vs brackets and semicolons.



    Not to hijack the thread but is there a way to write/read a register on the Pi to handle GPIO? I looked into it briefly and from what I saw it wasn't possible to access those memory locations as you would on a PIC MCU for example.
     
  15. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,912
    2,180
    Normally due to memory protection you can't directly write/read chip level registers on a RPi running Linux unless the program is running with kernel privileges. Nothing stops you from running 'bare metal' sans OS on the hardware just like a PIC MCU if that's your fancy but it's a complex task just to get beyond 'blink led'.

    http://www.valvers.com/open-software/raspberry-pi/step01-bare-metal-programming-in-cpt1/
     
    odm4286 likes this.
  16. odm4286

    Active Member

    Sep 20, 2009
    155
    5
    Interesting, feel free to tell me if the following question belongs in its own thread. How is it the Python libraries are able to write/read to these registers?
     
  17. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,912
    2,180
    The Linux kernel has standard access points for user program access of restricted resources like gpio. The usual method is with a file system (Sysfs) that can be opened, closed or modified. You can also write your own module to provide hardware access.

     
    Last edited: Jun 30, 2016
  18. hellifino

    New Member

    Jul 2, 2015
    19
    1
    Yes you can write directly to the GPIO registers and do all the bit banging you want by writing to the memory. Addresses are different for the different versions of the Pi. Just google "Raspberry Pi GPIO register address" and you should find it. Plenty of examples.

    No idea where @nsaspook is pulling that from. When you write to those addresses, you are directly controlling the hardware, no linux kernel involved. I've never had to do anything other than write to the memory address any RPi (don't have a pre-zero and 3 yet though).
     
  19. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,912
    2,180
    You can directly write GPIO physical addresses in bare metal supervisor mode as I said in my reply. With an OS like Linux with memory protection normally you would ioremap the GPIO address into kernel space via the MMU so you don't need to define an exact addresses in programs only offsets from the returned address so the code will run on different versions of the RPi without modification.

    https://raw.githubusercontent.com/nsaspook/daq_gert/master/daq_gert.c
    Code (Text):
    1.  
    2. /* Use the kernel system_rev EXPORT_SYMBOL */
    3. devpriv->RPisys_rev = system_rev; /* what board are we running on? */
    4. if (devpriv->RPisys_rev < 2) {
    5. dev_err(dev->class_dev, "invalid RPi board revision! %u\n",
    6. devpriv->RPisys_rev);
    7. return -EINVAL;
    8. }
    9.  
    10. dev->iobase = GPIO_BASE; /* bcm iobase */
    11. /*
    12. * dev->mmio is a void pointer with 8bit pointer indexing,
    13. * we need 32bit indexing so mmio is casted to a (__iomem uint32_t*)
    14. * pointer for GPIO R/W operations
    15. */
    16. dev->mmio = ioremap(dev->iobase, SZ_16K);
    17. if (!dev->mmio) {
    18. dev_err(dev->class_dev, "invalid gpio io base address!\n");
    19. return -EINVAL;
    20. }
    21.  
    22. devpriv->timer_1mhz = ioremap(ST_BASE, 8);
    23. if (!devpriv->timer_1mhz) {
    24. dev_err(dev->class_dev, "invalid 1mhz timer base address!\n");
    25. return -EINVAL;
    26. }
    27.  
     
    Last edited: Jul 24, 2016
  20. hellifino

    New Member

    Jul 2, 2015
    19
    1
    Actually your post wanted him to use a certain OS type. Point is, regardless of the OS (not that the OS has a choice), it is possible and not difficult. On every OS that runs on the Pi.
     
Loading...