• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
Maker Hacks

Maker Hacks

Ideas, news & tutorials for makers and hackers – Arduino/Raspberry Pi, 3D printing, robotics, laser cutting, and more

  • Home
  • About
  • 3D Printing
  • Laser Cutting
  • YouTube
  • Free Arduino Course
  • Recommendations
  • Contact

Running Raspberry Pi AND Arduino for the Best of Both Worlds

You are here: Home / Software / Running Raspberry Pi AND Arduino for the Best of Both Worlds
FacebookTweetPin
Author: Chris Garrett

Raspberry Pi and Arduino

I have been writing a lot more about Raspberry Pi than Arduino lately, but don’t get the impression I am leaving the Arduino world behind. Both devices have their benefits, and in fact, I believe they work really well together.

Let’s take a look at the easiest way to do that!

One of the Grove add-ons I bought recently was a very nice LCD display. Unfortunately, this display doesn’t have a Raspberry Pi library yet.

Now, of course, I can look at the Arduino library and figure it out, it is just i2c, but this is a nice opportunity to demonstrate how you can offload hardware to Arduino and leave the Pi to do the brainy stuff.

First, we connect the Pi and the Arduino via USB. Ensure Serial is enabled in your Raspi-Config too.

Arduino Side

Arduino Side

On the Arduino we can do some very simple LCD code (Gist here):

#include
#include
I2C_LCD LCD;
extern GUI_Bitmap_t bmlogo; //Declare bitmap data package.
uint8_t I2C_LCD_ADDRESS = 0x51; //Device address configuration, the default value is 0x51.
String instring;
void setup(void)
{
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
Wire.begin(); //I2C controller initialization.
LCD.CleanAll(WHITE); //Clean the screen with black or white.
// bitmap dispaly mode.
LCD.WorkingModeConf(ON, ON, WM_BitmapMode);
// display logo
LCD.DrawScreenAreaAt(&bmlogo, 0, 8);
// character mode
LCD.WorkingModeConf(ON, ON, WM_CharMode);
// 8*16 font size, auto new line, black on white background
LCD.FontModeConf(Font_6x8, FM_ANL_AAA, BLACK_BAC);
}
void loop(void)
{
LCD.CharGotoXY(0,0);
LCD.print("Hello World:");
while(Serial.available()) {
instring = Serial.readString();// read the incoming data as string
Serial.println(instring);
//Set the start coordinate.
LCD.CharGotoXY(0,32);
LCD.print(instring);
}
}

That should be mostly straightforward to read, but look out for the parts where the Arduino is waiting for input over serial, and sends whatever it is given to the LCD.

Raspberry Pi Side

Over on the Pi, we first add the serial module with

pip install serial

and make a note of the serial port from your Arduino screen as that is what we will send data too (ensuring the Arduino IDE is closed).

arduino

If you get any permissions errors then check your groups as you might need to add your user to the dialout group with sudo usermod -a -G dialout pi (where pi is my username).

As a last resort, try

sudo chmod 777 /dev/ttyACM0
sudo chown pi:pi /dev/ttyACM0

The Python code is really simple (Gist here):

import serial
import time
from datetime import datetime
print("Starting ...")
tardis = serial.Serial('/dev/ttyACM0', baudrate=9600) 
while(1):
    tardis.write(str(datetime.now()).encode())
    time.sleep(10)

Related

Category: SoftwareTag: arduino, Hacks, making, python, raspberry pi
FacebookTweetPin

About Chris Garrett

Marketing nerd by day, maker, retro gaming, tabletop war/roleplaying nerd by night. Co-author of the Problogger Book with Darren Rowse. Husband, Dad, 🇨🇦 Canadian.

Check out Retro Game Coders for retro gaming/computing.

☕️ Support Maker Hacks on Ko-Fi and get exclusive content and rewards!

Previous Post:pi entertainment centreLinux Automation Tips: Create a Boot/Start Menu with Python
Next Post:DJI/Ryze Tello Mini-Drone Review

Sidebar

  • Facebook
  • Twitter
  • Instagram
  • YouTube

Recently Popular

  • Gweike Cloud Review
  • How to choose the right 3D printer for you
  • Glowforge Review – Glowforge Laser Engraver Impressions, Plus Glowforge Versus Leading Laser Cutters
  • Prusa i3 Mk3S Review
  • Best 3D Printing Facebook Groups
  • xTool D1 Pro Laser Cutter Review
  • Elegoo Mars Review – Review of the Elegoo Mars MSLA Resin 3D Printer
  • Glowforge ‘Pass-Through’ Hack: Tricking the Front Flap of the Glowforge with Magnets to Increase Capacity
  • How to Make a DIY “Internet of Things” Thermometer with ESP8266/Arduino
  • Wanhao Duplicator i3 Review
  • IKEA 3D Printer Enclosure Hack for Wanhao Di3
  • Creality CR-10 3d printer review – Large format, quality output, at a low price!
  • 3D Printed Tardis with Arduino Lights and Sounds
  • Anet A8 Review – Budget ($200 or less!) 3D Printer Kit Review
  • Make your own PEI 3D printer bed and get every print to stick!
  • Upgrading the Wanhao Di3 from Good to Amazing
  • How to Install and Set Up Octopi / Octoprint
  • Creality CR-10 S5 Review
  • Glowforge Air Filter Review
  • Thunder Laser Review
  • 3D Printing
  • CNC
  • Hardware
  • Laser Cutting
  • News
  • Retro Computing
  • Software

amiga amos arduino basic programming budget buying cad cnc commodore corexy c programming creality crypto doctor who emulation esp32 esp8266 filament fpga glowforge Hacks Ideas kids lighting linux Makes making Monoprice Parts pc props prusa python raspberry pi ratrig resin Reviews robots software sounds technology tips upgrades wanhao xtool

.

Maker Hacks Blog Copyright © 2023 · All Rights Reserved · Powered by Mai Theme