Go to advanced search

by IanH2
Thu Oct 15, 2015 10:18 am
Forum: Python
Topic: help needed with skills
Replies: 3
Views: 714

Re: help needed with skills

If the students understand basic types like lists and dictionaries, why not try JSON? Something like this: import json datafile="scores.json" scores = [ # Name, win, lose, draw [ "Man City", 13, 1, 3 ], [ "Liverpool", 8, 4, 6 ], [ "Man U", 10, 3, 5 ], [ "Chelsea", 1, 13, 4 ], ] with open(datafile, "...
by IanH2
Mon Sep 07, 2015 9:45 am
Forum: Interfacing (DSI, CSI, I2C, etc.)
Topic: 1 to 2 UART Switch/Mux ?
Replies: 3
Views: 2061

Re: 1 to 2 UART Switch/Mux ?

If you're doing it all at 3.3V logic levels, a couple of 74HC157s (datasheet for NXP's version is http://www.nxp.com/documents/data_sheet/74HC_HCT157.pdf) will do the trick. For signals from the device to the Pi you connect the two devices to the HC157's -I0 and -I1 inputs, and the corresponding -Y ...
by IanH2
Sun May 24, 2015 4:59 pm
Forum: Interfacing (DSI, CSI, I2C, etc.)
Topic: USB Serial /dev/ttyUSB0 does not transmit
Replies: 3
Views: 1432

Re: USB Serial /dev/ttyUSB0 does not transmit

Have you checked that 'hardware flow control' is set to Off in minicom? If you have this On, it will not transmit unless the CTS (clear to send) line is active.

Ian
by IanH2
Mon Nov 17, 2014 4:11 pm
Forum: C/C++
Topic: Without \n
Replies: 2
Views: 665

Re: Without \n

Is it timing-related? If you replace the putchar() with, say, usleep(10000), does it still work?
by IanH2
Mon Nov 17, 2014 3:45 pm
Forum: Python
Topic: select on /dev/event/inputX does not work as expected
Replies: 2
Views: 633

Re: select on /dev/event/inputX does not work as expected

Have you tried strace-ing this, and matching the actual system calls with what the Python is doing? It's as if the Python read() call is taking all the available data anyway, and putting the 'leftovers' into a buffer somewhere.
by IanH2
Mon Nov 17, 2014 1:16 pm
Forum: Python
Topic: serial data wrong character set
Replies: 1
Views: 1010

Re: serial data wrong character set

It sounds like whatever's receiving these characters (minicom, GNU screen, ...) isn't being set to 7,E,2 correctly. 7,E means that instead of transmitting characters as 8-bit bytes, your equipment is transmitting 7 bits of data followed by 1 'even parity' bit. Parity is a simple error-detection code...
by IanH2
Thu Nov 13, 2014 2:38 pm
Forum: Python
Topic: Data received through serial, sent to email
Replies: 4
Views: 1303

Re: Data received through serial, sent to email

If it helps, I wrote up an introduction to using the serial port from Python at http://elinux.org/Serial_port_programming . If you're completely new to this, it's quite educational to connect the Pi's serial port up to a terminal emulator on a PC (with a USB-to-serial lead, or similar) so that you c...
by IanH2
Wed Nov 12, 2014 11:35 pm
Forum: Raspbian
Topic: Raspbian and systemd?
Replies: 91
Views: 43636

Re: Raspbian and systemd?

Does anyone apart from you care? In a word, yes. Anybody wanting to use a Pi for an embedded, headless or other 'non-desktop' application needs to know configuration basics: setting network parameters, enabling serial port access, setting permissions on hardware devices, configuring standard server...
by IanH2
Wed Nov 12, 2014 5:11 pm
Forum: Raspbian
Topic: Raspbian and systemd?
Replies: 91
Views: 43636

Re: Raspbian and systemd?

If both the officially supported distros (Raspbian & Pidora) are to use systemd, I would like the Raspberry Pi Foundation to formulate a considered opinion on the subject. The Pi has 3,000,000+ installed units; it's maybe the #1 platform for learning Unix. People will respect the Foundation's opinio...
by IanH2
Wed Nov 12, 2014 10:20 am
Forum: Python
Topic: GPIO.output possible fails
Replies: 6
Views: 1181

Re: GPIO.output possible fails

What voltage are you running the shift register at? The Pi GPIO is only 3.3V, and if the HC595 is running at 5V, that's very marginal according to the data sheet. If you can (safely) power the HC595 from 3.3V, try it and see whether the problem improves. If so, an easy fix would be to use an HCT par...
by IanH2
Tue Nov 11, 2014 7:05 pm
Forum: Raspbian
Topic: Raspbian and systemd?
Replies: 91
Views: 43636

Re: Raspbian and systemd?

Thanks - I knew about sysvinit, but it's clearly a non-standard option, and I'm not sure it's any more of a long-term fix than 'stick with Wheezy'. The mission of Raspberry Pi is surely to encourage people to understand how their systems work, and to learn by tinkering about and trying things. Syste...
by IanH2
Tue Nov 11, 2014 2:04 pm
Forum: Raspbian
Topic: Raspbian and systemd?
Replies: 91
Views: 43636

Raspbian and systemd?

Am I right in assuming that Raspbian will have no choice but to follow the Debian project and move to systemd for the next (Jessie) release? I have to say I'm not a big fan, and think it will make learning about, and tinkering with, the OS boot process considerably harder. The huge body of system ad...
by IanH2
Tue Nov 04, 2014 10:48 pm
Forum: Python
Topic: Python3.4 decoding byte string to anything else?
Replies: 2
Views: 1645

Re: Python3.4 decoding byte string to anything else?

It looks, from what you've posted, that line is already a string, and the b' characters are actually part of that string! You would get this effect if, say, x was a variable of type bytes , and somebody set: line = repr(b) A slightly hacky fix to strip these characters would be: line = line[2:-1] A ...
by IanH2
Tue Nov 04, 2014 10:34 pm
Forum: Python
Topic: python serial communication
Replies: 2
Views: 1061

Re: python serial communication

There's some useful information at http://elinux.org/RPi_Serial_Connection and http://elinux.org/Serial_port_programming . To get this to work you'll need to stop Linux using the serial port for its own purposes (see section 'Connection to a Microcontroller or other peripheral' on the first page).
by IanH2
Sat Oct 04, 2014 7:35 am
Forum: Python
Topic: Start a program with Python
Replies: 8
Views: 1593

Re: Start a program with Python

You wrote import subprocess subprocess.call(['kaku', ' m',' 1',' off']) What this does is like typing at the command prompt: kaku " m" " 1" " off" Probably this is causing an error in kaku. You need to remove the spaces at the start of the ' m', ' 1´, and ' off' arguments i.e. import subprocess subp...
by IanH2
Thu Aug 14, 2014 10:12 am
Forum: Beginners
Topic: power with PoE
Replies: 11
Views: 2472

Re: power with PoE

As it happens, I've just written up a project on Instructables about PoE with a Pi: See http://www.instructables.com/id/PiPoE-powering-a-Raspberry-Pi-over-Ethernet/ The Pi itself has an RJ45 connector with built-in 'magnetics' (isolation transformers for the data lines), and the type they use doesn'...
by IanH2
Wed Jul 09, 2014 9:36 am
Forum: Python
Topic: Retaining variables within functions
Replies: 27
Views: 3795

Re: Retaining variables within functions

But I'm not fond of globalising 'variables' and changing them within functions. I prefer to keep function variables exclusive. It's just a shame they seem to be 'forgotten' once the function ends! Your options are to either (a) use global variables, but isolate all the code which should have access...
by IanH2
Wed Jul 09, 2014 8:52 am
Forum: Python
Topic: using 2 serials
Replies: 10
Views: 2196

Re: using 2 serials

Your problem is this: try: # stuff except: pass OK, this is a slight lie - by itself this isn't making your code go wrong but it means virtually anything going wrong will be silently ignored. Even simple mis-spelt variable or function names throw exceptions rather than report syntax errors. Please d...
by IanH2
Mon Jun 16, 2014 12:45 pm
Forum: Python
Topic: Temperature sensor and MySQL
Replies: 3
Views: 3170

Re: Temperature sensor and MySQL

According to the MySQLdb user guide, you need to make the items into a tuple: c=db.cursor() max_price=5 c.execute("""SELECT spam, eggs, sausage FROM breakfast WHERE price < %s""", (max_price,)) In your example, something like this: curs.execute ("""INSERT INTO tablename values(CURRENT_DATE(), NOW(),...
by IanH2
Sat May 03, 2014 3:22 pm
Forum: Python
Topic: except SyntaxError
Replies: 7
Views: 2328

Re: except SyntaxError

Python 3 changes the 'except' syntax to make you use 'except SomeError as e', details at http://legacy.python.org/dev/peps/pep-3110/ . Running the program with 'python2' is much the easiest answer.
by IanH2
Sat May 03, 2014 3:09 pm
Forum: Python
Topic: Stop program after a period of time
Replies: 5
Views: 1062

Re: Stop program after a period of time

If the problem is that you have system calls (e.g. waiting for input) which might block for a long time, you can set an 'alarm'. The example at the end of https://docs.python.org/2.7/library/signal.html give the basic idea. (If this isn't a problem and you simply want to stop a loop, paddyg's code i...
by IanH2
Thu Apr 17, 2014 11:32 am
Forum: Interfacing (DSI, CSI, I2C, etc.)
Topic: Data diode (unidirectional comm) between 2 RPis
Replies: 28
Views: 12254

Re: Data diode (unidirectional comm) between 2 RPis

Are you 'allowed' to use public-key encryption here? If so, you can create a GnuPG or (ahem) OpenSSL keypair on your 'secure' pi and transfer the public key (perhaps using the data diode) to the 'online' one. The online one can encrypt data using the public key and write it to its own disk. It's qui...
by IanH2
Thu Apr 17, 2014 8:05 am
Forum: Python
Topic: Bluetooth LE and TI SensorTag from Python
Replies: 17
Views: 22003

Re: Bluetooth LE and TI SensorTag from Python

Basically, the only way to do this at the minute is to use a thread for each connection; there's no reason this shouldn't work. Alternatively, can you split the system into several programs (processes), where each process talks to one sensor, and writes an output file to disk (which is picked up by ...
by IanH2
Thu Mar 13, 2014 11:11 am
Forum: Interfacing (DSI, CSI, I2C, etc.)
Topic: Using 2n2222a as a switch for IR LEDs
Replies: 9
Views: 7320

Re: Using 2n2222a as a switch for IR LEDs

I'd be a bit concerned that 10mA from a GPIO pin and 300mA collector current is towards the high end of what the BCM2835 and 2N2222 can take; the transistor in particular is going to get hot and may not live very long. I would use a power MOSFET instead of a bipolar transistor - e.g. the FQP30N06L o...
by IanH2
Wed Mar 05, 2014 11:50 am
Forum: Interfacing (DSI, CSI, I2C, etc.)
Topic: USB to Serial for high speed data collection
Replies: 8
Views: 1982

Re: USB to Serial for high speed data collection

If you just need to record one logic input, you could using try the SPI interface: connect the signal to MISO (master-in-slave-out), set the clock rate to a suitably high speed, then do a long 'SPI read' operation. The master will output a clock on SCLK and sample MISO on each clock. This is deseria...

Go to advanced search