Pages: [1]   Go Down
Author Topic: Rhythmbox over Serial to LCD, for ppl with Linux!  (Read 1621 times)
0 Members and 1 Guest are viewing this topic.
Maastricht, Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

hey guys

I wrote a little python script that simply reads out Rhythembox and sends this to the Arduino over serial. Made a few adjustments to the LycuidCrystalSerial tutorial too, no it will go to the next line automatic. Edit the config parts in the code to your needs!

what to do:
Code for Arduino:
Code:
#include <LiquidCrystal.h>

// CONFIG //
int RS = 12;                  
int ENABLE = 11;
int d4 = 6;      
int d5 = 7;      
int d6 = 8;      
int d7 = 9;      
const int numRows = 2;
const int numCols = 16;
////////////

int i;
int empty;
int thisrow;

LiquidCrystal lcd(RS, ENABLE, d4, d5, d6, d7);

void setup()
{
  lcd.begin(numRows, numCols);
  Serial.begin(9600);
}

void loop()
{
  if (Serial.available()) {
    delay(100);
    lcd.clear();
    while (Serial.available() > 0) {
        for (int thisCol = 0; thisCol < numRows; thisCol++) {
          for (int thisRow = 0; thisRow < numCols; thisRow++) {
            lcd.setCursor(thisRow,thisCol);
            lcd.print(Serial.read(), BYTE);
            delay(200);
            i++;
            if (i == (numRows * numCols)) {
              i = 0;
              // this to clear the rest of the serial I/O
              while (Serial.available() > 0) {
                empty = Serial.read();  
              }
            }      
          }
        }
    }
  }
}


Python code
can be saved as a rbduino.py file and chmod +x rbduino.py the file so it will be executable. run it by ./rbduino.py (ask if you dont know what to do!)

Code:
#!/usr/bin/python
#Created By Patrick van der Leer a.k.a. Junke
#
#


### CONFIG ###
dev = "/dev/ttyUSB0"    # path to the arduino
rows = 2                # number of rows of your LCD
cols = 16               # number of cols of your LCD

###
import os, time
#from subprocess import Popen, PIPE

message = " "
song = "  "

def display():
  error = os.system('echo "%s" >> %s' %(message,dev,))
  if error == 0:
    print "Song '%s'" %(message,)
  else:
    print "Failed to display '%s'" %(message,)


### loop ###
while True:
  p = os.popen('rhythmbox-client --print-playing')
  song = p.readline()
  p.close()
  while len(song) < (rows * cols): # to make sure the arduino doesnt
    song += " "                    # fill the rest up with black
  if song != message:
     message = song
     display()
  time.sleep(5)


Logged

Maastricht, Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

had a little minor bug, the enter was displayed real strange as a few pixels after the name, new code bellow

Code:
#!/usr/bin/python
#Created By Patrick van der Leer a.k.a. Junke
#
#


### CONFIG ###
dev = "/dev/ttyUSB0"    # path to the arduino
rows = 2                # number of rows of your LCD
cols = 16               # number of cols of your LCD

###
import os, time
#from subprocess import Popen, PIPE

message = " "
song = "  "

def display():
  error = os.system('echo "%s" >> %s' %(message,dev,))
  if error == 0:
    print "Song '%s'" %(message,)
  else:
    print "Failed to display '%s'" %(message,)


### loop ###
while True:
  p = os.popen('rhythmbox-client --print-playing')
  song = p.readline()
  p.close()
  song = song[:-1]
  while len(song) < (rows * cols): # to make sure the arduino doesnt
    song += " "                    # fill the rest up with black
  if song != message:
     message = song
     display()
  time.sleep(5)
 
Logged

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi! Could you show us a picture of the display displaying the song to see the usability?

I suppose this will not stay on a breadboard, how do you plan to enclose it?
Logged

Maastricht, Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

sure, ill make a youtube movie of it somewhere tonight smiley

I haven't gotten any real plans to build it in because I only use netbooks lately. But I was planning on creating a box for the LCD screen but not for this purpose. It would be an option to build it in to a free slot of your 5'25 bay/CDROM on a desktop PC. found a little example of it, scroll all the way down, http://www.sorgonet.com/trashing/yourownlcd/

My personal goal is to monitor my car with the Arduino, allmost every car these days has an OBD-II port somewhere bellow the steeringwheel and above the pedals. To connect this through an IC to the arduino and let him display it on a LCD screen. I haven't figured out how I want to build it in so there for the little box idea.
Logged

Maastricht, Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset



 sorry about the bad quality bad it display's
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello Junkie,

Cool project! I went to replicate it today, I built the circuit up, created the python script, uploaded the code to the Arduino, but nothing happens! smiley-sad I have just started getting into Arduino and Ubuntu, and it would be sweet if I could get this working!

Currently, when I run the python script in the terminal, Rhythmbox loads as it should, and when I play a song, it appears in the terminal. As soon as it appears, the receive light on the arduino flashes a little, then the LCD quickly draws solid boxes all across the top line, then goes blank. I have not seen text at any stage.

Using the LCD Library and examples, I have had the LCD running, so it is not broken and my connections are good. Any suggestions?

BTW I am using Ubuntu 10.10 and Rhythmbox 0.13.1

Thanks in advance!
Fudge.
Logged

Maastricht, Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

are you able to display any messages on the screen?

You can test the code for the arduino by opening the terminal screen from the arduino compiler itself.

Which python version do you use, if i remember correctly the command popen doesn't exists in python 3 anymore.

Let me know if it works (and of course if it doesnt).

Ps great to see people are still building this!
« Last Edit: November 07, 2010, 04:33:38 am by Junke1990 » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey again Junke, thanks for the quick reply!

Ok, python then help() gives me version 2.6. When I run the script in terminal, it opens Rhythmbox. If I play a song, the title instantly appears in the terminal window. The arduino light flashes, black boxes start to appear on the screen, then disappear around 0.5 seconds later. However, opening the Serial terminal in the IDE, typing text and hitting enter, the Arduino dispalys it perfectly, even wrapping the line correctly.

So, if the block diagram is approximately like this,

Rhythmbox  ---  Python Script  ---  Terminal window  ---  USB cable  ---  FTDI chip  ---  Arduino  ---  LCD
      1                       2                            3                          4                    5                   6              7

I would say 1 is working, as is 4,5,6 and 7. I think there is something wrong between the python script and the data being transmitted. I will make a quick youtube video soon and upload, so show you my symptom.
Any other ideas?

Thanks again for all your help, can't wait to get this working, it's a great idea.

Regards,
Fudge.  
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As promised, Youtube video of the problem - sorry it is bad quality.



Regards,
Fudge.
Logged

Pages: [1]   Go Up
Jump to: