Moving a project from Arduino to Raspberry Pi Zero - Page 1
Forum section: electronics / general

author: aiq25
author_rank: Regular Contributor
timestamp: July 25, 2017, 08:32:32 pm
content: Hello. I'm working on a project that is currently using an Arduino but I would like to move it to a Raspberry Pi Zero. I think using the Pi Zero will be less hassle.Currently I have the following modules interfaced with an Arduino Nano: RTC, graphics LCD, SD card. Basically it's a fancy clock module with some added features. The reason I would like to move it to the Pi Zero is because I would like to be able to play large audio files with the module. I kind of got this working with the Arduino but I would like to try it on the Pi Zero. I would also like to use a bigger screen using the AV output of the Pi Zero.Are there any beginner tutorials anyone can recommend? I don't have any experience programming in Python or the Pi Zero. I have only worked with microcontrollers.

author: ealex
author_rank: Frequent Contributor
timestamp: July 26, 2017, 12:08:35 pm
content: short answer : it will be complicated.long one:i imagine you'll use the entire linux OS for it and not as a bare-bone system.the main code will run the same but you'll have to change the entire IO stuff:- no more raw access to RTC - you'll have to use C time functions or learn how to useI2C / SPI linux drivers or, if you're lucky you might be able to install a kernel module for your RTC so you can see it in /dev/ or make the OS use it as the main clock- no more raw access to LCD, etc- the same for user IO - you'll have to use GPIO system and learn how to enable / disable GPIO's and make the C code react on events- no more raw access to audio, etc - you'll have to spawn a mplayer process or something to play your audio filebasically you'll have to learn everything from scratch.C experience will help a lot, but still you'll have to learn the external libraries / etcsome other disadvantages :- you'll have to take care of the entire OS including specific SD wear problems / updates / install / etc- greater cost- greater power usagei'm doing the reverse of what you want: i'm using a RPI as a dev. system for some pulse-oximeter related code that will finally run on a cortex M0 micro.to make porting possible :- i made the low level I2C access as generic read / write functions that will be replaced with MCU specific code- all debug information on screen is generated from macros that i can change / disable easily- all data dumps are also handled by functions that can be disabled without changing the main code- i've used types from "stdint.h" - that are equivalent between system : uint32_t is an unsigned 32bit integer even if i'll build that code for a Z80

author: brucehoult
author_rank: Super Contributor
timestamp: July 26, 2017, 12:15:52 pm
content: If your only real problem is not enough storage space for large audio files then I think you'll have a LOT less trouble sticking to an Arduino and just adding an SPI flash chip or SD card. Or buying a "Arduino" with one built in.

author: hamster_nz
author_rank: Super Contributor
timestamp: July 27, 2017, 09:03:25 am
content: The way I would approach this with a Raspberry Pi is quite different to Arduino.- Get a Pi Zero W (with Wireless)- Use NTP to get the time over wireless, I would not use a RTC. Automatic timezone changes.- Use OpenGLes to do the display - making use of the GPU (seehttps://github.com/peepo/openGL-RPi-tutorialfor tutorial code). This will be the biggest challenge to learn.- Play audio files by fork()ing a process to play the audio streams- Use basic GPIO for any required local user interface (buttons/switches)- Do development remotely on the Pi over SSH.You can find some very poor C code to see how to use GPIO and I2C at its lowest userspace levels athttp://hamsterworks.co.nz/mediawiki/index.php/Raspberry_Pi- it is very old but you should get the gist especially for GPIO- you open a couple of special files and read/write values to them. One controls the pin direction (input vs output), the other reads the current value of the pin.This is all very old-school, but then I am that sort of guy.