1

Is there a way to use two LCDs with this script that uses TelNet to add strings to the screens?

#!/usr/bin/env python

import telnetlib;
import time;
import os;
import subprocess;

host='127.0.0.1';
port='13666';
data = ""



tn = telnetlib.Telnet(host, port)
tn.write("hello\r");

data += tn.read_until("\n");
tn.write("screen_add my_screen\n");
data += tn.read_until("\n");

tn.write("screen_set my_screen 1 -heartbeat off\n");
data += tn.read_until("\n");

tn.write("widget_add my_screen 1 scroller\n");
data += tn.read_until("\n");

tn.write("widget_add my_screen 2 scroller\n");
data += tn.read_until("\n");


var = 1;
while var == 1 :

  cmd1 = "mpc | head -1"        #gets the currently playing song from mpc
  process = subprocess.Popen(cmd1, stdout=subprocess.PIPE , shell=True)
  os.waitpid(process.pid, 0)[1]
  mpc_song = process.stdout.read().strip()

  cmd2 = "mpc | grep vol | cut -d% -f1 | sed 's/[^0-9]*//g'"    #gets the volume level from mpc
  process = subprocess.Popen(cmd2, stdout=subprocess.PIPE , shell=True)
  os.waitpid(process.pid, 0)[1]
  mpc_vol = process.stdout.read().strip()

  cmd3 = "mpc | head -2 | tail -1 | awk '{print $1}'" # gets the player state ie paused playing etc
  process = subprocess.Popen(cmd3, stdout=subprocess.PIPE , shell=True)
  os.waitpid(process.pid, 0)[1]
  mpc_state = process.stdout.read().strip()

  cmd4 = "hostname -I"  #gets the current ip of the boombox
  process = subprocess.Popen(cmd4, stdout=subprocess.PIPE , shell=True)
  os.waitpid(process.pid, 0)[1]
  ip_addr = process.stdout.read().strip()

  cmd5 = "netstat -t | grep rfe" #check if a user is connected via airplay
  process = subprocess.Popen(cmd5, stdout=subprocess.PIPE , shell=True)
  os.waitpid(process.pid, 0)[1]
  airplay = process.stdout.read().strip()

  cmd6 = "iwconfig wlan0 | grep Signal | awk '{print $4}' | cut -d= -f2" #check wifi signal strength
  process = subprocess.Popen(cmd6, stdout=subprocess.PIPE , shell=True)
  os.waitpid(process.pid, 0)[1]
  wifi_strength = process.stdout.read().strip()


  if airplay:  ##If airplay is in use, pause MPC and display Airplay Mode on LCD else display mpc data as normal
    mpc_pause = "mpc pause"
    process = subprocess.Popen(mpc_pause, stdout=subprocess.PIPE , shell=True)
    tn.write("widget_set my_screen 1 1 1 16 1 m 5 \"Airplay Mode\"\n");
    data += tn.read_until("\n");
  else:
    tn.write("widget_set my_screen 1 1 1 16 1 m 8 \"%s \" \n" % (mpc_song));
    data += tn.read_until("\n");
  timenow = time.strftime('%H:%M');
  tn.write("widget_set my_screen 2 1 2 16 2 m 4 \"Time:%s | Vol:%s | IP:%s | Signal: %s \"\n" % (timenow, mpc_vol,ip_addr,wifi_strength));
  data += tn.read_until("\n"); 

  time.sleep(5)

It looks really great but I don't know how to use it if you have 2 screens. Currently I am using the Pi pins for this script. But i have a MCP23017 so i can use that for the two screens.

2
  • Are the LCDs HD47780 based and hooked up something like this? Jun 5, 2013 at 10:08
  • Yes they are hooked up like that, and they are hd47780
    – user6827
    Jun 5, 2013 at 10:09

1 Answer 1

1

It looks like this script is designed to work with LCDproc.

You can either

  1. scrap the telnet part altogether and extend my example code. Basically you would replace all the tn.write(...) with a call to lcd_string. You'll have to work out what all the parameters do for the "widget_set ..." etc.

  2. Write a driver for LCDproc to support your setup

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.