rotcivisme
Posts: 6
Joined: Sun Nov 22, 2015 1:55 am

arduino with raspiberry pi

Sun Nov 22, 2015 1:58 am

Hi all,

I am having a little trouble with my code, I think it is just a syntax issue.

What I want to achieve is for the pi to play 50 different videos via keypad presses.
Pressing 01 will play 01.mp4, pressing 12 will play 12.mp4, pressing 30 will play 30.mp4 and so on.

Basically I have a keypad hooked up with arduino and it will output any 2 digit numbers via serial to the pi.
I was able to print out whatever the 2 digits pressed to display on the pi terminal.
However when I tried to have it play the video, it will display .mp4" not found.

I think there is just a syntax issue on this line of

Code: Select all

#    os.system('omxplayer -o local ' + videoNumber + '.mp4 &')

This is my pi code

Code: Select all

#!/usr/bin/env python2.7  

import serial
import sys, os

# some code to hide the terminal

os.system('clear')

device_port = serial.Serial('/dev/ttyACM0', 9600)

while 1:
    videoNumber = device_port.readline()
    videoNumber = videoNumber.strip('\n')

    print videoNumber 

    os.system('pkill omxplayer')
    os.system('omxplayer -o local ' + videoNumber + '.mp4 &')

device_port.close()
This is are arduino code if needed

Code: Select all

#include <Keypad.h>

const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// keymap
char keypad[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 9, 8, 7, 6 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 10, 11, 12 };

// Create the Keypad
Keypad kpd = Keypad(makeKeymap(keypad), rowPins, colPins, ROWS, COLS );

void setup()
{
  Serial.begin(9600);
}

int count = 0;
int keypresses[2];

void loop() {
  char key = kpd.getKey();

  if (key == '*' || key == '#'){
    count = 0;
  }

  else if (key) {
    keypresses[count] = key-'0';
    count++;
    if (count == 2) {
      Serial.println(keypresses[0]*10+keypresses[1]);
      count = 0;
    }
  }
}


Navyscourge
Posts: 258
Joined: Sat Oct 24, 2015 1:50 pm

Re: arduino with raspiberry pi

Sun Nov 22, 2015 11:20 am

I cannot test this at the moment, but try changing the line to

Code: Select all

    os.system('echo omxplayer -o local ' + videoNumber + '.mp4 &')
It should print the command line that you are generating, so you can see what is wrong with it (hopefully). You can also try typing the printed line at the prompt to see if it gives better error messages.

I also think you might need to use str(videoNumber) to convert the number to a string, but that line above will show you if this is neccessary, and allow you to make sure you have the line correct before trying to play the video

rotcivisme
Posts: 6
Joined: Sun Nov 22, 2015 1:55 am

Re: arduino with raspiberry pi

Sun Nov 22, 2015 5:26 pm

Navyscourge wrote:I cannot test this at the moment, but try changing the line to

Code: Select all

    os.system('echo omxplayer -o local ' + videoNumber + '.mp4 &')
It should print the command line that you are generating, so you can see what is wrong with it (hopefully). You can also try typing the printed line at the prompt to see if it gives better error messages.

I also think you might need to use str(videoNumber) to convert the number to a string, but that line above will show you if this is neccessary, and allow you to make sure you have the line correct before trying to play the video
Thanks for the reply.
I tried your method and it prints

Code: Select all

.mp4layer -o local videoNumber
(videoNumber being whatever digits were pressed.)

I also tried just a normal print command with

Code: Select all

print videoNumber + '.mp4 &'
and it will just print out .mp4 & without the videoNumber.

However if I just print videoNumber, the video number will be printed

It seems like it doesn't like anything after videoNumber, but fine it they are in front. So for example

Code: Select all

print '.mp4 &' + videoNumber
with print out .mp4 & videoNumber (videoNumber being whatever digits were pressed.)

I am not quite sure what you mean by the string or how that might work. But I did try to convert to number to a string with

Code: Select all

print str(videoNumber) = '.mp4 &'
with no luck. It still just prints the .mp4 &

any suggestions would be appreciated!

User avatar
joan
Posts: 14936
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: arduino with raspiberry pi

Sun Nov 22, 2015 5:57 pm

Try videoNumber.strip()

rotcivisme
Posts: 6
Joined: Sun Nov 22, 2015 1:55 am

Re: arduino with raspiberry pi

Sun Nov 22, 2015 6:22 pm

joan wrote:Try videoNumber.strip()
You are a God sent! Thank you so much!

Now it comes to a new question...
Is it possible to hide the code from executing? I have subprocess.call('clear') at the beginning, but that only seems to clear the codes whenever I re-run the python file.

cheers,

Return to “Troubleshooting”