Raspberry Pi 3 with Touchscreen and Camera V2

I love my wireless keyboard with trackpad.

1 Like

Yeh that looks like a good idea.

Was surprised that the Pi did not show up on the Particle IDE by itself on bootup. I had to run

particle-agent restart

So I made another desktop bash file called pi.sh file with

#!/bin/bash

particle-agent restart

and chmod 775 pi.sh

I know I can control the camera using python but does anyone know if I can control it using RobotC? I am going to try some other programming first.

..

Strange.. now when I reboot the Pi it does come online with the particle cloud without running my bash file.

..

I miss the Photon's crimson LED when I flash code, however the particle.io console does give me some feedback about online and offline and flash success

spark/flash/status success

@nrobinson2000 @Kurticus can someone explain this line at the docs

https://docs.particle.io/guide/getting-started/tinker/raspberry-pi/

Note that the Raspberry Pi does not have any analog inputs/outputs, so the functions available to each pin are not necessarily correct.

I assume all the GPIO pins can do an analogRead but it looks like only pins 13,16,18,19 can do PWM

https://docs.particle.io/datasheets/raspberrypi-datasheet/

I made this to try to understand it from the Photons point of view.

Serial: UART, SPI and I2C seem nicely labelled, but have to be activated in the preferences on the PI 3.

Hereā€™s another diagram I made that might help

Note: On both diagrams I changed PWM from: A5 GPIO 16 to A4 GPIO 12 since that is the results I am getting

This statement is only half true. The Pi does have PWM capable pins, but it does not have analog input pins. You can not do analogRead. The pins are labelled that way to help adapt libraries.

You can also address pins in your code using their GPIO names according to this pinout.

https://docs.particle.io/datasheets/raspberrypi-datasheet/#pin-out-diagram

The statement is fully true, but the notion that analogWrite() always produces an analog signal is wrong.
PWM is still digital.
Even on Photon and Electron there are only two ā€œanalogā€ output pins A3/DAC2 & A6/DAC and the Pi hasnā€™t any at all.

2 Likes

Hi @ScruffR thanks for joining the chat.

I was not expecting DAC pins on the PI. The four PWM pins is fine with me but I am a bit confused by everyone saying that we can't do analogRead on the PI. My staple of teaching reading sensors is based on the 0-4095 Analog range that works great on the Photon. Students can get pressure, temperature, flex and photo-resistor sensors working in minutes.

So how do I take an analog reading like 0-4095 on the PI? The PI Tinker program seems to be setup for AnalogRead.

int tinkerAnalogRead(String pin)
{
//convert ASCII to integer
int pinNumber = pin.charAt(1) - '0';
//Sanity check to see if the pin numbers are within limits
if (pinNumber < 0 || pinNumber > 7) return -1;

if(pin.startsWith("D"))
{
    return -3;
}
else if (pin.startsWith("A"))
{
    return analogRead(pinNumber+10);
}

#if Wiring_Cellular
else if (pin.startsWith("B"))
{
if (pinNumber < 2 || pinNumber > 5) return -3;
return analogRead(pinNumber+24);
}
#endif
return -2;
}

@rocksetta, to do analog input on the Pi, you would need an external SPI or I2C ADC board along with suitable software support, ideally for wiringPi.

2 Likes

AFAIK there is no special RPi targeted Tinker, so just the fact of having it in the general Tinker FW does not pose as proof that it should work on RPi.

@peekay123 WHAT!!! OMG.

I just looked at a hack method and the I2C method. Analog read is so easy on the Photon. I kind of was expecting an equivalent number of pins for analog reading on the PI.

Looks like I will not be purchasing a class set of PIā€™s, I can still use the faster processing and more memory and camera for specific student projects.

Since it is all I2C for analog read I would probably just purchase I2C sensors and skip the confusing ADC board (MCP3008 chip)

I2C Amazon Light Sensor , Temp Sensor

1 Like

@rocksetta, there are many Pi hats available which expand the Pi assortment of I/O including analog in and out (DAC). The Pi uses and ā€œAā€ class Arm processor designed to run fast and do GUI and other heaving processing. The ā€œMā€ class Arm processors used by Particle are designed for high-speed sensor interfacing and low-level stuff and thus the reason it has all those I/O goodies.

2 Likes

Ok. So the PI is awesome for everything except AnlogRead, So now lets do camera and sound.

A Python program can be used to run the camera https://www.raspberrypi.org/documentation/usage/camera/python/README.md

@peekay123 @ScruffR Can I run the Python Camera program using RobotC?? Can I run any executable program on the Raspberry PI from RobotC? I assume not since it seems like a security violation.

This isnā€™t a problem with the Arduino or Photon since everything can be controlled by RobotC, but with the Raspberry Pi other programs can also be running. I could bridge it with a web socket, but I feel their should be an easier way.

I just made something similar with Googleā€™s Tensorflow RNN Machine Learning, by running a python program from a PHP webpage.

https://quick-test-rnn-rocksetta.c9users.io/index.php

If that canā€™t be done, how can I control the Camera using RobotC . It looks like the camera is itā€™s own serial connection not I2C, SPI or UART, so control might be very difficult.

IFTTT might be an option.

Why would you need to use RobotC?

I'm still trying to understand what you are trying to do. You can control the camera from and call the Python script using Process Control, which basically lets you run bash commands as sudo.

Why not just make cloud funtions for controlling the camera?

1 Like

I did not know about process control. I think that will solve all of it.

https://docs.particle.io/reference/firmware/raspberry-pi/#process-control

Thanks @nrobinson2000

Using Process Control I can now run bash commands, send data to a program and receive output from the program. Very impressed! Well done particle.io :grinning: :grinning: :grinning:

1 Like

So this is working really well: Sound, Pictures, Videos all controlled by code calling a bash script on the Raspberry Pi that does the work. I use the console to get a bit of output.

I pre saved a file called siren.mp3 into the Music folder

My Raspberry PI is brand new so all programs used were pre-installed.
My starting point was the regular home folder, which is really at
cd /home/pi
I used these commands to make the bash script

cd Documents
touch cam-sound.sh
chmod 774 cam-sound.sh
nano cam-sound.sh

And enter the following:

#!/bin/bash

omxplayer -o local /home/pi/Music/siren.mp3

THEDATE=$(date +"%Y-%m-%d_%H%M")

raspistill -vf -hf -o /home/pi/Pictures/$1$THEDATE.jpg 2>&1

ls /home/pi/Pictures

raspivid -o /home/pi/Videos/$2$THEDATE.mp4 -t 3000 2>&1

ls /home/pi/Videos

omxplayer /home/pi/Videos/$2$THEDATE.mp4

echo "Picture and 3 second video taken at $THEDATE"
echo "You passed these variable $1 $2 $3"

save it and flash to the Raspberry Pi the following code:

// Testing sound image and video control from particle.io
// Open the console to see output
// video and sound from your Raspberry PI 3
// The Pictures will be saved in the /home/pi/Pictures folder right click and view them.
// By Jeremy Ellis Feb 21,2017
// MIT license

void setup() {

Process proc = Process::run("/home/pi/Documents/cam-sound.sh pic vid other"); // run a bash script with 3 arguments
proc.wait();

// int result = proc.out().parseInt(); // grab any integer output

Particle.publish("Command Line Output", proc.out().readString() , 60, PRIVATE);

String myExit = String(proc.exitCode(), DEC);
Particle.publish("Exit Code", String("Success = 0, your exit code =" + myExit), 60, PRIVATE);

}

void loop() {

}

I only had a few issues.

  1. Proc.in() did not work for me but I could pass variables in the main process::run command so it did not matter.

  2. I could not load my picture on the Raspberry PI touchscreen from my bash script or SSH even though the below code works fine from the Raspberry PI. gpicview /home/pi/Pictures/cam3.jpg

  3. The console only gives a bit of the output but you can view the entire output if you dig a bit. Remember \n means new line

  4. This stuff is very powerful. I am really pleased.

2 Likes

Next: 3D print a case, and test I2C, SPI and UART

@peekay123 any ideas, other than using GPIO pin numbers, of obvious issues I will face using your include files made for the Photon, but with the Raspberry PI. https://github.com/pkourany?tab=repositories

Quick question: Using the photon, on reboot a flashed program automatically runs. On the Raspberry Pi the flashed program runs when I flash it. (Probably good that it doesnā€™t run on startup, but if I wanted it to run on startup, what would be the command line statement?

I'm pretty sure particle-agent starts running the firmware when the Pi boots. @jvanier definitely knows the answer to this.

I am wrong. the particle-agent program does run on startup. However if I reboot the Pi properly it saves the Pictures and Videos, If I power off the PI the process still runs but the files are not saved. Probably a permissions issue.

The files that are saved with the proper sudo reboot procedure have root permissions. I view the permissions using this command:

ls -la

whereas if I save a file using nano "fred.txt" I have pi permissions.

-rw-r--r--  1 pi   pi         6 Feb 23 02:53 fred.txt
-rw-r--r--  1 root root 3776552 Feb 23 02:45 pic2017-02-23_0239.jpg
-rw-r--r--  1 root root 4192515 Feb 23 02:47 pic2017-02-23_0247.jpg

Note a big deal, I just need to shut the Pi down properly.

sudo reboot

or

sudo shutdown

I am a bit to used to shutting down the Photon by cutting the power.

UPDATE: On retesting everything seems to be running fine whether I do a normal reboot or shutdown the power. Not sure why I am getting strange results, but it seems fine now. Also when I first logged into the particle-agent it did not startup on reboot but now it does fine. Growing pains I guess.

Slow day today. I wanted to print a developer case for the Raspberry PI 3 with 7ā€™ Touchscreen and Camera but I didnā€™t like the full cases that I found on Thingiverse at

I just want something to give the setup a bit of strength without covering up all the pins etc.

Making my own one will take a bit (I tend to do about 8 prints until I like the product and this will take a couple of hours for each print) so I made a pin cover with labels for conversions from PI to Photon

Probably not my best idea and strangley hard to punch holes in the paper. The .stl file is on my Github site at

1 Like

Why not just edit the model and cut out space for the pins to be accessed?

I often use Tinkercad when quickly modifying models.

That would be much to sensible, I however like spending hours designing something that is just what I want. Case in point a nice cover for the photon that fits over the breadboard that comes with the photon maker kit.

The STL is at:

Yes I should use Thingiverse I just don't need another website to monitor.

1 Like