3 Replies Latest reply on Mar 9, 2015 9:34 PM by rgb

    Python, Wiring_x86, I2C LCD, Grove RGB LCD

    rgb

      Hi All
      I have been dabbling with the Galileo for a while now, trying to come up with ways of using it, and thought that it might be useful for others if I shared what I have put together in one place and, hopefully, get some feedback on how to improve on what I have done.
      I decided to use the Wiring-x86 as the other options don't really fit my needs as well.

       

      Wiring_x86 from Emutex Ltd  works on the Edison, Galileo Gen 1 and Galileo Gen2 boards, but only with the standard Intel and AlexT's uClibc versions of Yocto for the Galileo, as hasn't been ported to the XDK IoT version (see https://communities.intel.com/message/241845#241845 for a discussion of different versions). It includes examples for analog and digital reading and writing and Jack Pien created an example using PWM to control servos. Also, thanks to help of AlexT. Sergey's blog and Alexander Merz I have been  able to use  Raspberry Pi libraries to control I2C and SMBbus LCDs, and have been able to port a Raspberry Pi Grove LCD library from  Dexter Industries.

       

      Setting up to use Python on Galileo
      1. Install Emutex library (https://github.com/emutex/wiring-x86)
      Download, uncompress and copy to the Galileo. I suggest creating a “wiring” directory on /media/realroot so as to not use up the limited space on the virtual Busybox partition.
      Look at examples to see how to use the library to control the GPIO pins. For Galileo Gen 1 boards you need to change the references from GPIOEdison  to GPIOGalileo.

       

      2.Install smbus and i2cTools

      You need to make sure you have python-dev installed prior to doing the following

      opkg update

      opkg install python-dev

      ******
      The following is from Alexander Merz's message  at https://communities.intel.com/thread/52982
      Download i2c-tools-3.1.1.tar.bz2, from http://www.lm-sensors.org/wiki/I2CTools
      Uncompress the file and rename the uncompressed directory to i2ctools
      Copy contents to /media/realroot/i2ctools
      Edit smbusmodule.c  in py-smbus directory. Around line161, change the constant I2C_SLAVE to I2C_SLAVE_FORCE
      Go back to the i2cTools directory
      run# make EXTRA="py-smbus"
      This will create the i2c-tools, then install them:
      then run# make install
      This will install tools i2cdetect and i2c
      Go back to the  py-symbus directory
      run# python setup.py install
      You should now have SMBus installed and can call it from Python programs

       

      To use a I2C backpack adapter for a 16x2 or 20x4 LCD, you  need to activate the i2c bus and install i2c LCD library
      Sergey's blog  http://www.malinov.com/Home/sergey-s-blog shows how to set the MUX for the GPIO . You can use echo commands to export GPIO29, set the direction  to “out” and set the value to 0 or run the following Python program.
      ----------------------------
      #!/usr/bin/python
      with open("/sys/class/gpio/export","w") as fh:
           fh.write("29")
      with open("/sys/class/gpio/gpio29/direction","w") as fh:
           fh.write("out")
      with open("/sys/class/gpio/gpio29/value","w") as fh:
           fh.write("0")
      -----------------------
      You can now run i2cdetect -r -y 0 to see the i2c devices. If you leave off the -y you will get a warning message about accessing an SMBbus and running i2cdetect may cause problems, so you may have to reboot.

       

      3. Set up Raspberry Pi library to access i2c LCD
      Go to http://www.recantha.co.uk/blog/?p=4849
      Copy and create
      i2c_lib.py
      lcddriver.py
      lcd.py

       

      The Raspberry Pi uses I2C bus 1, so you need to change the reference to 0.
      In the file i2c_lib.py
      change the line: def __init__(self, addr, port=1):
      to port=0

       

      4. Set up Raspberry Pi Library to access the Grove RGB LCD
      My university also received some Galileo Grove kits, so I am seeing if I can use the sensors and LCD screen. The sensors are standard analog and digital sensors, so don't really need anything special that isn't already in the Wiring library. The LCD screen is, however, a bit different. It uses SMBBus commands, not I2C, so needs a different library than the I2C backpack LCD described earlier.
      I found a few libraries for the Grove LCD, but the best seems to be the one  made by Dexter Industries  for the Raspberry Pi
      See more at the the GrovePi Site (http://dexterindustries.com/GrovePi/)
      Attached is my hack of the Dexter Industries' library and a sample program.

      You need to run the python program mentioned above to access the I2C bus for the library to work
      Hope this is helpful to someone

       

      Attached is the Wiring directory from my Galileo that includes the examples from Emutex Ltd  modified to run on a Galileo 1 (I haven't tested them all, but unless  I made a typo changing Edison to Galileo, they should work. There are also the libraries for I2C, the backpack LCD (lcddriver.py) and for the Grove LCD, plus a few others example programs using a DFRobot motor shield, PIR sensor, servos, the I2C LCD  and Grove RGB LCD, that I have been dabbling with.
      regards
      rgb

       

      Message was edited by: Richard Bradley Forgot to mention that python-dev has to be installed, corrected

        • 1. Re: Python, Wiring_x86, I2C LCD, Grove RGB LCD
          rgb

          First, the above script to set up I2C has only been tested on the Galileo Gen 1. The Gen 2 uses a different setup for I2c so will need its own setup.

          (Edit: scroll down to see how to set up Galileo Gen 2 to use i2c)

          Running Python Scripts automatically

          Now that the system is up and running, the next item is to have scripts run automatically when the system starts. The scripts can be as simple as displaying the IP address and hostname or running your Zombie detection system that monitors the environment and sends you a picture of any stray Zombies that wander into your area.

          This is actually quite easy to do.

          In the /etc/init.d directory is a file called galileod.sh, which is the last script called before login. I tried to create a script and have it run, but ran into problems as the Python Path wasn't set so python couldn't find its libraries.

          Anyway you just need to create the python script, such as the attached testLCD.py, that shows the hostname and IP address and then a test message.

          Then open /etc/init.d/galileod.sh with your favorite editor and add a line to the start aglileod() section, such as the bolded line below

          ------------------------

          start_galileod()
          {
              echo "Starting galileod"
              start-stop-daemon -q -S -m -p $pidfile -b -x $launcher
              start-stop-daemon -q -S -m -p $pidsreset -b -x $sreset -- -i $input_reset_gpio -o $output_reset_gpio
             /usr/bin/python /media/realroot/wiring/testLCD.py&

           

          }

           

          Save and reboot and, if you have a I2C LCD attached to you system, you will see your Hostname and IP address

          enjoy

          rgb

          • 2. Re: Python, Wiring_x86, I2C LCD, Grove RGB LCD
            rgb

            Hi All

            ALexT has posted more programs to the repository so you can skip the part in #2 of the instructions above about installing i2ctools and smbus and just run

            opkg update

            opkg install i2c-tools

            opkg install i2c-tools-dev

            opkg install python-smbus

            opkg install python-smbus-dev

             

            He also added espeak

            so you can add them with

            opkg install espeak

            opkg install espeak-dev

            Now, with a cheap USB sound card and Web Cam,  you can use aplay to play sound files, arecord to record, espeak to do test to speech, fswebcam to take pictures and wiring_x86 to control GPIO for buzzers, lights, animated toys, etc

            So nothing is keeping you from making a web controlled, emailing, security chicken to protect you cookies from you dieting relatives after Christmas :-).

            Like an improvement on the below

            Raspberry Pi - Helps Keep New Year Resolutions - and protect your biscuits and cakes - YouTube

            regards

            rgb

            • 3. Re: Python, Wiring_x86, I2C LCD, Grove RGB LCD
              rgb

              Hi All

              I now have python working with i2c on Gen2 boards, at least with the Grove RGB LCD.

              After studying the information put together by Emutex EmutexLabs

              I made the following program which sets up the pins for use and I can now send messages to the Grove LCD. I haven't tried to use the i2c backpack LCD as it uses address 27 which is used by the Galileo board. I will need to solder across the jumpers to set the address to something that doesn't conflict.

              #!/usr/bin/python
              with open("/sys/class/gpio/export","w") as fh:
                  fh.write("60")
              with open("/sys/class/gpio/gpio60/direction","w") as fh:
                  fh.write("out")
              with open("/sys/class/gpio/gpio60/value","w") as fh:
                  fh.write("0")
              with open("/sys/class/gpio/export","w") as fh:
                  fh.write("19")
              with open("/sys/class/gpio/gpio19/direction","w") as fh:
                  fh.write("out")
              with open("/sys/class/gpio/gpio19/value","w") as fh:
                  fh.write("0")

              You can run this and then run the GroveLCDTest.py I included in the first posting.

              Hopefully this is helpful to someone

              rgb