yenyu88
Posts: 5
Joined: Sat Jun 06, 2015 4:54 am

How to read data from USB input

Sat Jun 06, 2015 5:05 am

Hi guys,

Currently I'm doing my final year project with the use of Raspberry Pi.

Concept: Energy Monitoring using Raspberry Pi.

I've bought myself a Raspberry Pi and a Energy Monitoring Set. Since the Energy monitoring has a USB output to connect to a computer, but rather to save cost in a long run, I'm connecting it to a Raspberry Pi which is using a different OS platform. Thus I'm enquiring on how am I able to read out the data and store it in a file and finally graph it out into charts/graph in terms of 1-Hour, 6-Hours, 24-hours and even a week usage.

I've setup my basic Raspberry Pi, and tried googling about this topic but it isn't that clear, and would like to seek insight on this function with the use of python language.

Thanks all for the insight in advance.

Regards,
Newbie Raspberry Pi User,
Yen Yu

yenyu88
Posts: 5
Joined: Sat Jun 06, 2015 4:54 am

Re: How to read data from USB input

Thu Jun 11, 2015 2:23 am

Any experts can help out? :)

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: How to read data from USB input

Thu Jun 11, 2015 2:25 am

What is the energy monitoring USB device?

Can you plug it in and print the result of

Code: Select all

lsusb
?

betruk
Posts: 36
Joined: Fri Apr 24, 2015 8:17 am

Re: How to read data from USB input

Thu Jun 11, 2015 6:44 am

Same problem at my side, any solution?

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: How to read data from USB input

Thu Jun 11, 2015 6:46 am

betruk wrote:Same problem at my side, any solution?
Same suggestion.

What is the energy monitoring USB device?

What is the USB vendor ID and product ID?

User avatar
rpdom
Posts: 17694
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: How to read data from USB input

Thu Jun 11, 2015 8:14 am

As ame says, first step is to identify the device. Use "lsusb" (That's lower-case "LSUSB", not "1SUSB").

Then find out if there are suitable drivers for it.

Then look for any documentation on how to communicate with it.

yenyu88
Posts: 5
Joined: Sat Jun 06, 2015 4:54 am

Re: How to read data from USB input

Sat Jul 04, 2015 4:09 am

Hello guys,

Sorry for the long late reply cos my equipment got faulty and waited for a 2 week replacement. I got my equipment yesterday. I've keyed in lsusb, and it shows as follows

Bus 001 Device 004: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port.

Do you guys means to google the above product ID and documentation and look for the communication method?
But how do i implement it in python to allow my raspberry to continuously pulling data from it?

Regards,
Yen Yu

fruitoftheloom
Posts: 24427
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: How to read data from USB input

Sat Jul 04, 2015 4:41 am

This is a little out of date but may give some pointers:

http://raspberrypi.stackexchange.com/qu ... ial-device
Thinking outside the box is better than burying your head in the sand...

User avatar
DougieLawson
Posts: 40119
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: How to read data from USB input

Sat Jul 04, 2015 4:47 am

A pl2303 should be recognised and auto identified as /dev/ttySx - the dmesg command will tell you what tty device it is.
Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: How to read data from USB input

Sat Jul 04, 2015 4:56 am

Ok, so it's just a serial port. You don't need anything special, just open the port and you can send and receive data.

yenyu88
Posts: 5
Joined: Sat Jun 06, 2015 4:54 am

Re: How to read data from USB input

Sun Jul 05, 2015 4:43 pm

Alright, I understand. But how am I able to open the port and read specific data from the port using Pyhton source code?
Because my project requires the reading of Power (Watt/kwH) measurement from time to time. Thus i believe within python code, there must be a line for the raspberry pi to prompt or pull the data. (E.g. probing every 1min or so).

User avatar
B.Goode
Posts: 10725
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: How to read data from USB input

Sun Jul 05, 2015 6:16 pm

yenyu88 wrote:how am I able to open the port and read specific data from the port using Pyhton source code?
One way is to install and use the python-serial module.

It can be installed via:

Code: Select all

sudo apt-get install python-serial
The documentation, including example code, is here: pyserial.sourceforge.net

User avatar
mikronauts
Posts: 2817
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: How to read data from USB input

Sun Jul 05, 2015 8:06 pm

You need the documentation for your "Energy Monitoring Set", specifically, how it sends the readings via the usb serial port.
yenyu88 wrote:Hi guys,

Currently I'm doing my final year project with the use of Raspberry Pi.

Concept: Energy Monitoring using Raspberry Pi.

I've bought myself a Raspberry Pi and a Energy Monitoring Set. Since the Energy monitoring has a USB output to connect to a computer, but rather to save cost in a long run, I'm connecting it to a Raspberry Pi which is using a different OS platform. Thus I'm enquiring on how am I able to read out the data and store it in a file and finally graph it out into charts/graph in terms of 1-Hour, 6-Hours, 24-hours and even a week usage.

I've setup my basic Raspberry Pi, and tried googling about this topic but it isn't that clear, and would like to seek insight on this function with the use of python language.

Thanks all for the insight in advance.

Regards,
Newbie Raspberry Pi User,
Yen Yu
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

texy
Forum Moderator
Forum Moderator
Posts: 5160
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: How to read data from USB input

Mon Jul 06, 2015 11:18 am

FYI, the
Bus 001 Device 004: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port.
is a very common standard usb-to-serial chip. It doesn't tell you what hardware you are connecting.
If you can give and google the actual make and model number of the
Energy Monitoring Set
then you may be able to see if this has been done before and follow that example.

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

yenyu88
Posts: 5
Joined: Sat Jun 06, 2015 4:54 am

Re: How to read data from USB input

Wed Jul 08, 2015 6:21 am

Hi Guys,

I've did a few search. I manage to find the manual, but it doesn't say about how the USB to Serial communicates.

https://cdn.shopify.com/s/files/1/0510/ ... uction.pdf

texy
Forum Moderator
Forum Moderator
Posts: 5160
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: How to read data from USB input

Wed Jul 08, 2015 6:29 am

Then you need to ask the manufacturer, or think of a new project!
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: How to read data from USB input

Wed Jul 08, 2015 6:31 am

On page 28 they ask you to download the software from their website. That's probably not going to help you. Instead, you could email the company and ask them for details about the protocol. If that doesn't work you'll need to be a detective.

The first thing you need to know is the baud rate of the device. Try something popular like 4800, 9600 or 115k (or just try all of them until you get something sensible). It is possible that the unit will send data out periodically, so you just have to capture that data and look at it. Or maybe you are supposed to send a command to the unit to get some data out. Unfortunately, without the protocol details you are in the dark.

You could also download their software and run it on another PC, then hook something up (maybe hardware, maybe software) to capture the data going between their software and the unit, and examine it later to figure out the protocol.

Return to “Beginners”