Fixing unresponsive touch on PiTFT with PyGame

I have a 2.8 PiTFT which I’ve used on my Pi 1 and just set it up on a Pi 2. I tried to get Adafruit’s FreqShow working with the screen, and it would display, but was unresponsive to any touch inputs. I know touch was working in X Windows otherwise, and had ran through all the calibration tools in the PiTFT setup instructions, so something else was wrong.

Some Googling later, turns out the PiTFT and PyGame (used by FreqShow) works ok on Raspbian Wheezy (which I have on my Pi 1), but not on Jessie (which I have on my Pi 2).

Trick is to replace libsdl with the prior/older version from Jessie – a script to do the replacement is in the post linked about. Ran the script, and now FreqShow works on the PiTFT 2.8 great. Shame there’s no audio out as well, but a cool use for the small screen.

Fixing wifi dropouts on Raspbian / Raspberry Pi

From this article, if you’re using one of the Wifi dongles on a Pi 1 or 2 (Pi3 has built in wifi), you can prevent the random dropouts during periods of inactivity by:

sudo nano /etc/modprobe.d/8192cu.conf

and then paste in and save this:

options 8192cu rtw_power_mgnt=0 rtw_enusbss=1 rtw_ips_mode=1

and then reboot.

Getting started with node.js, Express and Mongoose

I started tinkering with some test data creation scripts using Node.js a while back, but it’s been on my todo list to dig deeper into some Node. I recently walked through this very good article, and got a REST based backend using Node.js, Express and a MongoDB up and running in less than an hour. Pretty good going for learning a new tech stack 🙂

After putting together the app from the steps in the article, I realized there was a few steps that could have been simplified. For example, instead of hand coding the package.json as in the article, you can let npm update it for you by passing the –save option. So, to create an initial package.json:

npm init

and walk through the prompts.

Next, instead of manually adding the dependencies for Express, Mongoose and body-parser, again, use npm to install and add them to the package.json file with –save:

npm install express --save

npm install mongoose --save

npm install body-parser --save

That saves some work – no need to edit the package.json file by hand when the tool maintains it for you. Without the –save option npm still downloads the dependency, but –save writes the details into your package.json as well.

Using Mongoose with Express certainly gets you up and running with basic CRUD using REST pretty quick and easy with minimal coding. I was surprised how little code it takes to get the basics implemented. I’ve shared my version of the completed app to GitHub for future reference here, and for quick reference below:

[code]

var express = require(‘express’);
var app = express(); //init Express
var bodyParser = require(‘body-parser’);
var mongoose = require(‘mongoose’);
var Contact = require(‘./app/models/Contact’);
mongoose.connect(‘mongodb://nodetest:yourpassword@localhost:27017/nodetest’);
//init bodyParser to extract properties from POST data
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

var port = process.env.PORT || 8080;

//init Express Router
var router = express.Router();

//default/test route
router.get(‘/’, function(req, res) {
res.json({ message: ‘App is running!’ });
});

router.route(‘/contacts/:contact_id’)
// retrieve contact: GET http://localhost:8080/api/bears/:bear_id)
.get(function(req, res) {
Contact.findById(req.params.contact_id, function(err, contact) {
if (err)
res.send(err);
res.json(contact);
});
})
// update contact: PUT http://localhost:8080/api/contacts/{id}
.put(function(req, res) {
Contact.findById(req.params.contact_id, function(err, contact) {
if (err) {
res.send(err);
}
else {
contact.firstName = req.body.firstname;
contact.lastName = req.body.lastname;
contact.save(function(err) {
if (err)
res.send(err);

res.json({ message: ‘Contact updated!’ });
})
}
});
})
//delete a contact
.delete(function(req, res) {
Contact.remove({
_id: req.params.contact_id
}, function(err, contact) {
if (err)
res.send(err);

res.json({ message: ‘Successfully deleted contact’ });
});
});

router.route(‘/contacts’)
// create contact: POST http://localhost:8080/api/contacts
.post(function(req, res) {
var contact = new Contact();
contact.firstName = req.body.firstname;
contact.lastName = req.body.lastname;

contact.save(function(err) {
if (err)
res.send(err);

res.json({ message: ‘Contact created!’ });
});
})
//GET all contacts: http://localhost:8080/api/contacts
.get(function(req, res) {
Contact.find(function(err, contacts) {
if (err)
res.send(err);

res.json(contacts);
});
});

//associate router to url path
app.use(‘/api’, router);

//start the Express server
app.listen(port);
console.log(‘Listening on port ‘ + port);
[/code]

Splitting an mpeg4 file into multiple parts with ffmpeg

I have a 5.3GB mpeg4 file (of the just released ‘From Bedrooms to Billions: Amiga Years‘ documentary about the Commodore Amiga – I haven’t watched it yet but may post a review later), and the size of this single file is giving me some issues 🙂

It’s too large for a FAT32 formatted flash drive, since the largest file you can store on that file system is 4GB. It’s also too large to burn to a 4.7GB single-sided DVD. So I could have reformatted a flashdrive to exFAT (I don’t think the PS4 reads NTFS drives, and my Mac won’t write to NTFS, at least not without other drivers), but the easiest option is probably to split the file to smaller parts.

Now, if you’ve done any video editing before, rendering 1080p video and any amount of transcoding to different formats takes a ton of time. I didn’t want to recode the video or change the format in any way, I just wanted to split the file.

Turns out ffmpeg will do exactly this, and to split into 2x 1hr15m smaller files only took a few minutes on my i7 Mac. I took suggestions from this question, and ended up with these two commands:

ffmpeg -i inputfile.mp4 -ss 00:00:00.0 -c copy -t 01:15:00.0 outputfile-pt1.mp4

ffmpeg -i inputfile.mp4 -ss 01:15:00.0 -c copy outputfile-pt2.mp4

The first one takes input from the start and for 1hr15mins writes to the output file, and the second starts from 1hr15min into the input file and writes the remainder from that point onwards to the second output file.