Another little project- RFID Python

In Introduction to Programming course, students are required to complete a project that solve a problem they investigated. One of the tool/gadget we provided is an RFID reader.

A year ago when we ran the course a group of student found out keeping the track running time is a huge challenge for the PE department. An RFID reader was purchased for students to solve this problem.

One critical challenge was the communication between the RFID reader and python. In order to solve it the serial connection has to be established and the data has to be interpreted.

As this is still an introductory level course, students are asked to focus on the data processing part and assume that there will be a function acquiring the RFID and they need to handle the logic. In other words, the hardware and serial communication part has to be written for them.

After weeks we finally have a solution!

Library used: pySerial, codec
Python version: 3.5 or up

Here’s the code, more information to come

import serial, sys, time
import codecs

ard = None

def getCardId(rawCode):
    headerStr = "1b390100110010603000"
    returnId = -1
    try:
        decodestr = codecs.encode(rawCode, 'hex')
        returnId = str(decodestr).split(headerStr)[1]
        return returnId
    except:
        return -1

def initReader():
    global ard
    port = '/dev/tty.SLAB_USBtoUART'
    ard = serial.Serial(port, baudrate=115200,timeout=5)

def readRfid():
    global ard
    rawCode = ard.read(24)
    return getCardId(rawCode)

initReader()

#an infinite loop that reads the rfids
while True:
    print(readRfid())

Fun problem solving for LightLogo

It has been a while since I post anything here and it feels great when I have something to share :)- Geeky content warning~

So Brian and I are both very much into playful invention and we’ve been working together on various projects. Recently I helped him ordered 30 Arduinos and some neopixel ring from mainland China. The Arduino board is a clone so it is not using the USB-Serial chip (FDTI compatible) comes with the original Arduino. It uses something called CH340 and the driver could be found here.

Brian is using LightLogo  as the platform for students to apply their logo code on some tangible hardwares. The package from the site doesn’t work with the clone, so what’s wrong?

Observations

  1. When using the assembler.jar in the lightlogo-vm directory, the TX/RX light on the clone arduino doesn’t work, which suggests that the code cannot be loaded to the board.
  2. When running the LightLogo.jar in the lightlogo directory, an error message “device not found” was shown.
  3. I tried to open the sourcecode using Eclipse (as it is java based), gave me a lot of insight on how LightLogo was written (a bunch of LContext/Function and parameters…), the file that I spent most time on was MacSerialHandler.java, which extends the SerialHandler.java with a function called “usbInit”, but it is an empty method!

Thinking…

  1. In Arduino/Processing when I tried to access the serial port I need to specify which port I’m using, in Linux/Mac this is done by referring to a file/device path.
  2. For the original Arduino UNO, according to the Arduino environment (Tools-Ports), the original board has a port name called (cu.usbserial1411), and the “clone” has a port name called “cu.wchusbserial1410”. There are few other ports that we can find in the directory /dev/cu.*
  3. Where in the LightLogo code does it specify the port???

After looking through all the .java file with no luck, I started looking at the assembler.logo file, which is the script written in the logo language, and bingo!

to find-mac-port

dolist [i files "/dev][if member? "cu.usbmodem :i [output :i]]

dolist [i files "/dev][if member? "cu.usbserial :i [output :i]]

output "

end

Obviously these few lines of code are they key! It is trying to find a port called “cu.usbserial” instead of “cu.wchusbserial”, so “naturally” I modified the code to

to find-mac-port

dolist [i files "/dev][if member? "cu.wchusberial :i [output :i]]

dolist [i files "/dev][if member? "cu.usbmodem :i [output :i]]

dolist [i files "/dev][if member? "cu.usbserial :i [output :i]]

output "

end

And it worked!

So in order for the LightLogo.jar to run, modify the same code (*Update [11/21/2016]: I should have mentioned the compiler.logo has be changed as well in order for it to work, thanks @briansmith and @tylerbeatty!) and you can download the logo script to Arduino 🙂

Happy problem solving!

*Brian if you read this message can you send me some screen capture/picture of the ring so this post won’t be that dry? Thanks!

Livestreaming with BM TV Studio

Situation
We have an ATEM TV Studio Switcher (https://www.blackmagicdesign.com/hk/products/atemtelevisionstudio) in the shop, which allows us to connect up to 9 cameras at the same time with a neat IP based control interface. It sounds like perfect solution for live streaming and event (HDMIs->ATEM TV Studio->Youtube), but challenges surfaced quickly.

The ATEM TV Studio has a USB connector which sends the mixed feed as an H.264 stream, in order to stream a video feed to youtube, we can choose from Wirsecast/FlashMediaLiveEncode (FMLE). Unfortunately, none of them works with the BM ATEM TV Studio Switcher.

Luckily, livestream.com provide a free livestreaming software called Procaster (http://www.livestream.com/userguide/?title=Procaster), which supports the BM interface out of the box!

We ended up stream the feed through livestream.com and use OBS (https://obsproject.com/download#obs2_dl), an opensource broadcasting program as the ultimate solution.

Because the unverified livestream.com channel can only serve up to 50 people, we use the screen/window capturing function of OBS to capture and re-broadcast the stream to youtube to work around this. Soundflower is being used for redirecting sound from the programme to OBS.

Connection map

Primary stream
Cameras —HDMI/SDI—>BM ATEM TV Studio—USB—>iMac—->Livestream Procaster—>livestream.com channel

Mirrored stream (through another computer)
Chrome (Opening livestream.com as a popup)–>OBS–>Youtube

Sound mixing
Another challenge we had was to mix the sound from the sound panel with the SDI video feed supplied by the video company. As the sound panel only provides XLR output and we didn’t have any USB sound capturing device, we used the Sony HDV camera as a XLR->HDMI convertor to the BM ATEM interface. Which worked pretty well.

Self learning and textbook

Just watched Good Will hunting over the weekend in memory of Robin Williams. How a teacher inspire students in an elite school in Dead Poet Society was certainly up-lifting for me as an educator. The friendship/brotherhood in Good Will Hunting was also touching. A scene in the movie made me think about what learning is/could be.

Not everyone has the incredible memory that Will has in the movie, but we have access to the books he read. The interesting thing is what he chose to read, not just any book but textbooks! It really is the quickest way of diving in any field if you know nothing about it. I may start with the recommendations on this page and keep an eye on the College Open Textbooks (http://www.collegeopentextbooks.org/) project.

CSV to XML tool

When working on a small website project, the client sent an excel file for the database. However this time I intended to use pure XML instead of database, so a CSV->XML tool is needed.

http://www.convertcsv.com/csv-to-xml.htm

This website is exactly the tool I wanted. You can simply upload the CSV and it will convert it to XML for you. You can specify the root and record name for the XML file, makes it an even better tool!

Investigation- Identify the requirements of the project

The project brief is simple, come up with some new services and technology that can justify or reinforce the role of library in a school.

Most people started by finding new technologies and new services, to me, it is more important to rethink how education may look like in the future, so that we can easily imagine how the library can evolve to adapt to this new teaching and learning landscape.

“21st century education” is a popular term that coined by many educational scholars and educators. So let’s start by looking at the trend of this education development.

I found this article (http://www.innovationunit.org/knowledge/our-ideas/21st-century-learning) very useful as it points out the role of students, educators and schools in the new era of education. It suggested that students learn through meaningful projects, school as a base camp for enquiry learning, educators regard themselves as learners as well as teachers and Learners collaborate in their learning, rather than ‘consuming’ it.