Long playing for 1000 years

May 10, 2016 at 8:59 pm (computers, music, Uncategorized) (, )

I first stumbled across the Longplayer project when I saw a mention of their Longplayer for Voices on Kickstarter.  Then I completely forgot about it until Christian Payne (Documentally) mentioned that he’d caught up with the originator of the project on his long-form, email newsletter, ‘Backchannel’ at which point I looked it up again.

The project is great – a very long-term musical project (a bit like As Slow as Possible) conceived and composed by Jem Finer.  The one line summary is that he has recorded a sequence of music for some ‘singing bowls’ and the project combines various processed versions of this 20 minute piece in a range of different ways, resulting in a piece of music that will play continuously for 1000 years without repeat.  The long version can be found on the about page for the project (its worth a read).

To listen along, there is a live stream available from the website or listening stations in a couple of locations in London and San Francisco.  There are a series of live performances too where players play extracts of the piece.

And more recently there is now an iOS app that uses the same 20 minute piece, the same time-driven algorithm and a sense of shared time via the Internet to make the app play exactly the same part of the music available in the physical spaces and via the web.

The ‘score’ is a simple representation, with six concentric rings showing the sounds in six variations of the 20 minute piece.  But the algorithm behind Longplayer will play each ring at different speeds – with one of the rings taking 1000 years to complete.

There is a visual representation of the score with an indication of which part of each ring is currently playing.  This is available via the web and the iOS app.  The following show four stages of the app over a 24 hour or so period.

Notice how the second ring progresses the quickest, but some of the others hardly at all.  The third ring is the 1000 year ring, so over 24 hours there is no movement at all

2016-05-06 21.00.352016-05-06 23.15.362016-05-07 06.15.482016-05-07 13.13.332016-05-07 17.27.24

A great app, a great project and fascinating music!

Kevin

 

Permalink Leave a Comment

Custom Blockly Block “does not know how to generate code”

March 8, 2016 at 10:56 pm (computers, kids) (, )

I’m playing around with my Espruino board (embedded board, programmed with JavaScript) as part of my quest to find a kid-friendly embedded controller.  One of the nice things about Esruino is that it comes with a Web-based IDE that provides a terminal console that allows you to write JavaScript directly onto the board or allows you to programme it using Blockly.

I want to write some custom blocks, so downloaded the source for the EspruinoWebIDE and did the following:

  • Created a new file “EspruinoWebIDE\blockly\blockly_myfile.js”
  • Included this file in a SCRIPT tag in the top of “EspruinoWebIDE\blockly\blockly.html”
  • Proceeded to create my blocks – initially as defined using the Google BlockFactory and then added to blockly.html to present them in the UI

There are already a few files defining extra blocks – blockly_espruino.js is the main one and blockly_robots.js is a simpler one, that actually makes quite a good example to follow if you are doing your own.

The basic idea is that there is a ‘toolbox’ definition for your block in the blockly.html file (which makes it appear in the menu of blocks in the user interface), supported with a block-definition file detailing the physical appearance of the block and what it needs to connect to within the user interface (Blockly.Blocks.mycategory_myblock) with an accompanying code-generation block.  In this case, generating JavaScript via Blockly.JavaScript.mycategory_myblock that uses the Blockly API to get what it needs from the user interface and returns a string that contains the corresponding generated code.

There is a setting in the EspruinoWebIDE – Settings->General->Overwrite JavaScript with Graphical Editor – which is quite handy at this point, as it means that every time you hit ‘Send to Espruino’ in the graphical editor, the JavaScript window is updated with the generated code.

Except when it isn’t.  There were no obvious errors, and the ‘Send to Espruino’ always said ‘Sent’ but there was no outward sign that anything had happened.

If you use the Inspect option of the Chrome browser then it was apparent that there was a JavaScript error:

Language “JavaScript” does not know how to generate code for block type “mycategory_myblock”

This hidden message indicates that there is a miss-match between the Blockly.Blocks.mycategory_myblock function and the Blockly.JavaScript.mycategory_myblock function and even though the block is available through the user interface, Blockly doesn’t know how to generate code for it.

Except in my case, no matter how it was written, generated, typed or checked, it was ignoring my code and I just could not spot what the error was.  Eventually, I changed the order of the SCRIPT statements in blockly.html, wondering if there was some kind of load-order issue and it suddenly started working.  Once I changed the order back again, it kept on working – so unfortunately I have no idea what was causing the problem, but just guessing some weird local caching issue or something not picking up my changes.

But if you are finding things aren’t working but there are no visible errors, definitely try Inspect and look for JavaScript errors and see if you can somehow force the application to re-load all files from scratch to make sure you aren’t working with an old version or something similar.  I still don’t know why it started working, but at least it works now.

The only reason I’ve written this is that Googling for various hints as to what might cause the issue was failing me – even once I knew what the error was.  So thought I’d write it down myself in case others have a similar issue – this might give someone else a clue.

Despite this rather irritating issue, I actually quite like Blockly.

In a future post, I’ll talk a bit more about what I’m actually doing with all this.

Kevin

 

 

 

Permalink Leave a Comment

Codebugs, Glowbugs and DIY Tails

February 20, 2016 at 11:21 pm (computers, kids) (, , , , )

We got a couple of Codebugs just before Christmas and have been having quite a good time playing with them so far.  You write code for them using an online IDE based on Google Blockly and the device itself has two buttons, a 5×5 grid of LEDs and 4 GPIO ports with nice croc-clip friendly contacts on it so you can straight away start playing with linking code to the physical world.   It also has an expansion connector (the ‘Tail’) and when you connect it to a PC via USB it comes up as a mass storage device and you drag code across to it to run it.

We’ve done the obligatory “scroll your name” across the LEDs, hooked up fruit to create a fruit ‘touch’ keyboard and have started exploring some of the projects available via the online community.

My only slight gripe is that the mechanism for getting code on it isn’t quite as intuitive as it might be.  We’ve largely got the hang of holding buttons down whilst powering it up.  although, when trying out code, it tends to stay plugged in, so we use the ‘reset’ then ‘hold’ technique designed for when it is powered by battery most of the time.  However sometimes the buttons aren’t held quite long enough for it to register.  Also, every time it comes up in mass storage mode, the previous programme is erased.  If you are not careful you end up with lots of “compiled” Codebug programmes lying around your browser’s download directory.  Seeing as all projects are managed by the online IDE it would be nice if there was a neater way to send the code straight to the Codebug without copying between directories.

That aside, its a great device and has generated lots of interest with the kids and I’ve recently purchased a set of Glowbugs.  These are WS2812 based RGB LEDs with simple croc-friendly (of course) contacts that you connect to the Codebug using the GPIO, configure and off you go.

For our next project however, we quite wanted to use all 4 GPIO as inputs and I know that the Glowbugs can be driven directly via the expansion header, so I set about seeing if I could create a DIY ‘tail’ connector to breakout the CS, +5v and GND connectors, as used by the Colourtail, to something that would accept croc clips.

I also have a cheap, purchased from China, 24-LED WS2812 pixel ring with the same +5, GND, DIN, DOUT interface as Neopixels and the Glowbugs that I wanted to use.  I’ve already connected this up via the Codebug Tail, but again wanted something croc-clip friendly that the kids could use.

So armed with a 20x80cm prototyping board and some right-angled headers, I set about making a simple DIY tail adaptor and connector for the LED ring.  Warning – massively dodgy soldering coming up.

fig1.png

As a major goal was to make this easy for the kids to use, I wanted the connectors to break out in the same order as the Glowbugs – so (with all boards face down) this means from left to right, GND, DIN, +5v.  However the tail connectors are CS, GND, three not required for this application, and VCC, so I needed a wire link to get CS (for the data) from the left-most pin to a central spot.

fig2.png

With a small portion of board cut and smoothed ready for headers, I decided to use crude solder blobs as a simple way to create croc-friendly pads and connections, as can be seen via the very dodgy soldering going on in the following!  In case you can’t quite make it out, the ‘circuit’ is highlighted in the last pic.

fig3.png

So after adding another three ‘pads’ on the other side, the final thing looks like this.

fig4.png

In order to be able to easily use the LED pixel ring, I decided on a similar approach to add some ‘pads’ to the ring.  Once again I wanted the pads in the same order as a Glowbug.  I could have added both an ‘in’ and ‘out’ connector, but decided for simplicity only to create an ‘in’ – so the ring will always be the last thing in the chain.  In the following, the wires are coloured as follows: green is GND, blue is DIN and red is VCC.

fig5.png

The biggest problem with just connecting the pixel ring directly to the Tail connector was the poor physical connection of the wires to the ring itself, so this time to give it a degree of kid-robustness, I used a hot-glue gun to stick the pads to the ring and protect the solder links.

fig6.png

With a final blob of glue over the top of the solder connections to the ring, everything is ready to go.

fig7.png

So to use the Glowbugs connected via the DIY tail, you have to use the configuration blog to enable the ‘Colourtail’ rather than ‘Glowbug’, but otherwise, everything else is just the same.  And of course, the ring is just treated as a set of additional 24 Glowbugs added on the end of the chain.

So crude, and soldering that will definitely not be winning any prizes, but it works, and passes first contact with the kids.

fig8.png

Kevin

 

Permalink Leave a Comment

Severe consequences of losing your data?

February 5, 2016 at 5:09 pm (internet, kids, moan, security) (, , , , , )

I read this article from TheRegister with mild interest:

“Medical Data Experiment goes horribly wrong: 950,000 records lost” – http://www.theregister.co.uk/2016/01/27/centene_loses_95000_medical_records_on_six_hard_disks/

Ok, so yet another ‘company loses personal data, warns as a precaution’ story.  In this case, six hard disks apparently containing personal health information of around 950,000 people.

So my initial thought was something along the lines of “are people really misplacing whole hard disks still in 2016”?

Personally, I suspect it is more likely an accounting problem rather than a physical loss – they are probably labelled up wrong, or left in a drawer somewhere, or have been re-used and nobody noticed, that kind of thing.  But it is interesting to look at the phraseology of two consecutive press releases from the company involved (no, I’m not quite why I looked them up either – but I did!).

On the data loss:

Centene Announces Internal Search of Information Technology Assets

“Centene has determined the hard drives contained the personal health information of certain individuals who received laboratory services from 2009-2015 including name, address, date of birth, social security number, member ID number and health information. The hard drives do not include any financial or payment information.  The total number of affected individuals is approximately 950,000.”

Fair play – they are admitting their mistake and attempting to do the right thing:

“Notification to affected individuals will include an offer of free credit and healthcare monitoring. Centene is in the process of reinforcing and reviewing its procedures related to managing its IT assets.”

Otherwise, without openness and honesty around such issues, how can lessons be learned?

But the following day, the next press release announces their financial results for the year:

Centene Announces Preliminary 2015 Financial Results

“On January 25, 2016, the Company announced an ongoing comprehensive internal search for six hard drives that are unaccounted for in its inventory of approximately 26,000 information technology (IT) devices.  This incident resulted from an employee not following established procedures on storing IT hardware.  While we cannot estimate the impact with certainty at this time, the Company does not expect the impact of the incident to have a material effect on its future growth opportunities, financial position, cash flow or results of operations.”

Yes – they don’t expect the fact that 950,000 people’s personal health details going missing will affect their financial position now or in the future.

I guess that answers the question of why it is 2016 and companies still lose whole hard disks of personal information.  If there is minimal financial impact, it is good business sense for them to keep their procedures at the minimum deemed necessary – that is just sensible business risk-management.   In fact the whole ‘free credit and healthcare’ monitoring could be seen as a cost effective insurance policy against possible loss should it occur, compared to the costs of labour intensive, fault-free asset management to prevent any chance of loss up front.

These things will only change when the impact of the issue impacts the companies involved much more significantly, rather than just ending up a problem for the people whose data is lost.

In the UK, I guess we have the Information Commissioner’s Office guidelines for handling data and ability to set fines, but even this misses the point for me.  A fine is after the fact and with so many charities and volunteer organisations (cough, Scout National database) storing personal details, a significant fine would end up burying an organisation and an insignificant fine is largely pointless.  But either way the data will still be lost.  So the answer to this one is really education – so to that end, the ICO Guide to Data Protection is great – but unless someone is actually auditing and proactively educating organisations, or perhaps more appropriately companies now selling online services to organisations, on these principles, I suspect we’ll keep seeing problems occurring.

As we see massive growth in companies providing online payment services (ParentPay, SchoolMoney, PaySchool and so on) information and content management (dbPrimary, Google for Education, etc), communications and mailing services (ParentMail, etc), biometric authentication (40% of secondary schools apparently), online learning, and so on to education and charities, more of our data ends up online regardless of the fact it might not be us putting it there!  For a cash-strapped organisation, managing an offline and online database isn’t going to happen.  You might not use their online system, but your data will be there as they’ll be using it themselves.

The school use of biometrics is particularly  worrisome – many kids may have their biometrics compromised before they are even old enough to decide for themselves if they want to hand over their biometric signatures to any company.

Fundamentally, at present, all the risk from a company storing your data is on you, not them.  Until that risk balance is addressed, I guess we will stay at the mercy of “bottom line (non-)impact” reporting.  And whilst it is convenient and cost-saving for organisations to use more of these online services, our data will keep being stored who knows where and there is very little we can do to stop the tide of information uploading.

Kevin

 

 

Permalink Leave a Comment

How much? I could buy a computer for that!

January 18, 2016 at 9:17 pm (computers, internet) (, , )

First there was the C.H.I.P. – the $9 computer with built-in Wifi.  Then soon after that appeared on Kickstarter, the Raspberry Pi Zero came out – a $5 Raspberry Pi.  Ok, so strictly speaking you need a few accessories to really get them going as fully fledged computers as most people would recognise the term, but in these days of cheap computers, it made me think, just how does this compare with other ‘everyday’ items?

So, taking the “list price” for the Pi Zero, as £4 … that is:

Of course, these days, $5 will get you  a whole range of goods and services, including, according to Dave Gormon, 5000 Twitter followers!

And of course, as per the tweet that started the thinking behind this ramble … just slightly more than a 10 minute bus trip in Cambridge!

Kevin

 

Permalink Leave a Comment

ArduBlockly and the Arduino Nano

January 2, 2016 at 4:33 pm (computers) (, , )

I’ve been wanting to find a scratch style interface for Arduino to see if I could do something simple Arduino and Lego wise for the kids.  We have a CodeBug (which is pretty good for learning basics of programming for LEDs and I/O – maybe the topic of another block post, but see http://codebug.org.uk/ if you are interested) which is programmed using a web-based environment based on Google Blockly.  We’ve also used Scratch, so these were my two starting points.

After some googling, I found ArduBlockly, ArduBlock BlocklyDuinoS4A (Scratch for Arduino) and Snap.  As far as I can see, ArduBlock doesn’t seem to be maintained at the moment, Snap looks like an enhancement on S4A and ArduBlockly looks inspired by BlocklyDuino.

Snap looks particularly interesting and I’ll take a look at that at some point, but I went with ArduBlockly as it has a ‘download and just run all-in-one’ installation.  As far as it goes, this largely worked quite well – the only problem is that at present, it doesn’t support the Arduino Nano, which is what I was hoping to use.

However, seeing as this is basically using a Python web server to serve the Blockly interface to a browser, and then using the Arduino IDE (at least v1.6) directly to interface with the hardware, I had a poke around to see if the Nano could be slotted in.  The answer is yes and no.

The ‘all in one’ nature of the beast means that the Python is compiled into something that just runs, so isn’t editable anymore.  However, if I was happy to install Python and use a browser directly, I could hack it about.

Note: the following will hopefully become redundant at some point as support for the Nano I’m sure will be forthcoming, but it is documented here for my own reference right now.

In order to add the Nano enough for me to start playing, from some googling and searching around on github, there are three files that appear to require editing:

ardublockly/classic/settings.html

In the ‘Arduino Board’ selection form, a new <option> is required whose value is ‘nano’.

ardublocklyserver/compilersettings.py

There is a __Arduino_type array which needs to include

'Nano': 'arduino:avr:nano'

as an option.

blockly/generators/arduino/boards.js

This defines the properties for the different support boards, so an entry for the Nano is required.  This is largely the same as the ‘uno’ entry, but the Nano has two additional analogue pins.  This is unverified, as I’m not an Arduino expert (to use at your own risk), but I believe all that is required is to create an entry as follows:

Blockly.Arduino.Boards.nano = {
  name: 'Arduino Nano',
  description: 'Arduino Nano with ATmega328p board',
  analogPins: Blockly.Arduino.Boards.generateAnalogIo(0, 7),
  digitalPins: Blockly.Arduino.Boards.generateDigitalIo(0, 13).concat(
                   Blockly.Arduino.Boards.generateAnalogIo(0, 7)),
  pwmPins: Blockly.Arduino.Boards.uno.pwmPins,
  serial: Blockly.Arduino.Boards.uno.serial,
  serialPins: Blockly.Arduino.Boards.uno.serialPins,
  serialSpeed: Blockly.Arduino.Boards.uno.serialSpeed,
  spi: Blockly.Arduino.Boards.uno.spi,
  spiPins: Blockly.Arduino.Boards.uno.spiPins,
  spiClockDivide: Blockly.Arduino.Boards.uno.spiClockDivide,
  i2c: Blockly.Arduino.Boards.uno.i2c,
  i2cPins: Blockly.Arduino.Boards.uno.i2cPins,
  i2cSpeed: Blockly.Arduino.Boards.uno.i2cSpeed,
  builtinLed: Blockly.Arduino.Boards.uno.builtinLed,
  interrupt: Blockly.Arduino.Boards.uno.interrupt
};

Then running the ArduBlockly application using the ‘start.py’ script rather than the stand-alone ‘ardublockly_run’ batch file seems to allow me to use it with my Nano.

I was getting ‘Arduino Exit Code: 259’ as an error though, and something somewhere online suggested that the arduino_debug.exe should be used for the diagnostics from the command line, rather than your arduino.exe, so I updated the ArduBlockly preferences to use arduino_debug.exe and now I get a successful build and download.

Aside – I couldn’t get ArduBlockly to work in MS new browser (Edge), so I use it with Chrome, connecting to the local URL generated by the running Python script of http://localhost:8000/ardublockly/

(If I ever get around to getting GitHub going properly and assuming this is verified as the right way to add the board, I’ll submit it back).

I look forward to see how ArduBlockly develops, and do wish to try Snap at some point too (especially as at present, with the above hack for the Nano, it is no longer the simple ‘all in one’ application for installing on a PC that the kids could use).  However, it is early days for ArduBlockly development, and so far the signs are looking pretty good to me!

Kevin

 

Permalink Leave a Comment

MIDI Arp

December 1, 2015 at 11:17 pm (computers, internet, music) (, , , , )

I wanted to do something with MIDI and Arduino.  I’ve just picked up some cheap Arduino Nano Ethernet shields, based on the Microchip ENC28J60, so thought I’d combine the two.  The ENC28J60 and a cheap Arduino Nano makes for a very compact and economical Ethernet ready microcontroller and I have a nice Roland MT-32 Synth module gathering dust that I wanted to try again.

2015-12-01 21.16.05

My initial idea was to use MIDI to trigger sounds based on arp requests received by the Arduino, (hence the name MIDI Arp), but then decided that on my home network arp requests wouldn’t give a lot of variation, so I decided to see if I could trigger on the destination IP address of any packet received.

First I needed the MIDI interface.  I followed the simple circuit and example provided on the Arduino website, but wanted it all self-contained inside a MIDI plug rather than on a breadboard, so I soldered up the 220 resistor inside a 5 pin MIDI DIN plug as follows (MIDI pins are number 1, 4, 2, 5, 3 for some reason):

  • Arduino GND – Brown – MIDI Plug pin 2
  • Arduino 5v – Red – 220 Ohm resistor – MIDI Plug pin 4
  • Arduino TX (Pin 1) – Orange – MIDI Plug pin 5

This was then connected to the Arduino and the MIDI test programme showed that all works fine.

2015-12-01 21.16.212015-12-01 21.19.13

So, to the Ethernet side of things.  The following is an excellent starting place for the ENC28J60 based nano shield:

After reading this, I decided to use the UIPEthernet library as my starting point as I liked the idea of a plug-in replacement to the standard Arduino Ethernet library.  There was two major things to work out – first, how to set the device into some kind of promiscuous mode, assuming it supports it at all; second how to grab the destination IP address from any received packets.

From the ENC28J60 data sheet, the key register that controls the receiver filtering is the Ethernet Receive Filter Control Register – ERXFCON (see section 8 ‘Receive Filters’).  There are a number of modes for filtering and the UIPEthernet library is set up to filter for the unicast address associated with the MAC address configured for the module, for broadcasts, and to use the pattern matching filter to spot arp packets.  It turns out that to set the receiver into promiscuous mode, this register just has to be set to zero.

Now this is where things got lazy.  I just dived into the UIPEthernet library sitting in my Arduino library folder and hacked about. I might tidy this up one day and do it properly.

The low-level driver code can be found in utility/Enc38j60Network.cpp.  In the Enc28J60Network::init function, there is a line that sets up the ERXFCON register:

writeReg(ERXFCON, ERXFCON_UCEN|ERXFCON_CRCEN|ERXFCON_PMEN|ERXFCON_BCEN);

This needs to simply be changed to clear the register:

writeReg(ERXFCON, 0);

Next, how to store the destination IP address.  Again, simplicity ruled this one too.

The high-level interface to the library can be found in UIPEthernet.cpp and UIPEthernet.h.  I added two public functions and two private variables to the UIPEthernetClass class in UIPEthernet.h:

public:
  IPAddress lastSrcIP();
  IPAddress lastDestIP();
private:
  static uip_ipaddr_t uip_lastipsrc;
  static uip_ipaddr_t uip_lastipdest;

Then in the UIPEthernet.Cpp file, added the code to store the last source and destination IP addresses from received packets.

First, define a structure to dig into to the IP header (a bit of a layer violation, but I wasn’t after neat designs really).  Add the following after the definition of ETH_HDR near the top of the file.

#define IPBUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])

Then add two (static) global variables to the file:

uip_ipaddr_t UIPEthernetClass::uip_lastipsrc;
uip_ipaddr_t UIPEthernetClass::uip_lastipdest;

Add two accessor methods to retrieve the last source and destination IP addresses (with appropriate conversion to the Arduino Ethernet friendly IPAddress format):

IPAddress UIPEthernetClass::lastSrcIP()
{
  return ip_addr_uip(uip_lastipsrc);
}
IPAddress UIPEthernetClass::lastDestIP()
{
  return ip_addr_uip(uip_lastipdest);
}

Finally add the code to save the addresses to the UIPEthernetClass::tick() function, on reception of a packet.

          Enc28J60Network::readPacket(in_packet,0,(uint8_t*)uip_buf,UIP_BUFSIZE);
          if (ETH_HDR ->type == HTONS(UIP_ETHTYPE_IP))
            {
              uip_packet = in_packet; //required for upper_layer_checksum of in_packet!
#ifdef UIPETHERNET_DEBUG
              Serial.print(F("readPacket type IP, uip_len: "));
              Serial.println(uip_len);
#endif
              uip_arp_ipin();
              uip_input();
              if (uip_len > 0)
                {
                  uip_arp_out();
                  network_send();
                }
                // Extra code added here
                uip_ipaddr_copy(uip_lastipsrc, IPBUF->srcipaddr);
                uip_ipaddr_copy(uip_lastipdest, IPBUF->destipaddr);
                // Extra code ends
            }

That should be all that is required to expose the destination IP address of any received packet via the UIPEthernet class (ok, breaking compatibility now with the standard Arduino Ethernet library).

The arduino sketch file now consists of the following:

/*
MIDI based on 
 http://www.arduino.cc/en/Tutorial/Midi

UIPEthernet Examples used for rest
NB: Requires hacked UIPEthernet Library!
 */
#include <SPI.h>
#include <UIPEthernet.h>
#include "IPAddress.h"

int lastIP;
int thisIP;

// Initialise note array with whole tone scales in octaves 3 through to 6
// C3 = 36
// C4 = 48
// C5 = 60
// C6 = 72
// C7 = 84
#define NOTES 24
int notes[NOTES] = {
  // C3  D3  E3  F#3 G#3 A#3
     36, 38, 40, 42, 44, 46,
  // C4
     48, 50, 52, 54, 56, 58,
  // C5
     60, 62, 64, 66, 68, 70,
  // C6
     72, 74, 76, 78, 80, 82
};

void setup() {
  //  Set MIDI baud rate:
  Serial.begin(31250);

  // Initialise the uIP and UIPEtherent stacks
  uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05};
  IPAddress myIP(192,168,0,6);
  
  lastIP = 0;
  thisIP = 0;

  Ethernet.begin(mac,myIP);
  
  // Initialise patch using program change
  // 32 = Synth 1, Fantasy
  midiCmd (0xC0, 32);
}

void loop() {
  Ethernet.maintain();
  IPAddress sip = Ethernet.lastSrcIP();
  IPAddress dip = Ethernet.lastDestIP();
  thisIP = 256*dip[2] + dip[3];
  
  if (thisIP != lastIP)
  {
    lastIP = thisIP;
  
    int note = (thisIP & 0xff) % NOTES;  // Scale to number of notes
    int vel  = ((thisIP & 0xff00) >> 8)/4;        // Scale to val between 0 and 64

    //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
    noteOn(0x90, notes[note], 16+vel);
  }
}

//  plays a MIDI note.  Doesn't check to see that
//  cmd is greater than 127, or that data values are  less than 127:
void noteOn(int cmd, int pitch, int velocity) {
  Serial.write(cmd);
  Serial.write(pitch);
  Serial.write(velocity);
}

void midiCmd(int cmd, int val) {
  Serial.write(cmd);
  Serial.write(val);
}

The final byte of the IP address determines which note from the array of notes to play (modulo the number of notes) and the third byte determines the volume to be used, scaled and with a minimum specified.

There is a control message to set the voice on the MT-32 to Synth1-Fantasy as this sounds suitably ambient. There are no note-off messages, so notes are allowed to keep ringing. As the note array defines four octaves of whole tone scales, the running-on notes create quite an interesting effect.

2015-12-01 21.40.12

There seems to be a regular drone set up, which I think is due to the IP address of my PC and router. These two addresses provide a sort of default back-drop of sound to anything else going on.

In order to get anything useful though, it would be no good just using a port on the router, as even the dumbest, cheap modern router will tend to do some MAC level filtering on ports. I had a laptop and the Arduino plugged into an old Netgear En104 4-port Ethernet hub, which has no intelligence (as far as I know) built in – so the Arduino could see everything coming out of the laptop.

The results were quite pleasing. Google has a nice enhanced drone to it. You can really hear the clutter of a site that is pulling in ads from all over the Internet – such as Amazon or YouTube or a news site.

Edited to add:  Here is a short video below showing them being opened.  It’s a bit crude but you get the general idea.

 Maybe next, I’ll see if I can do the same with a Wi-Fi link for the Arduino instead of wired Ethernet.  It might also be worth trying different scales and alternative mappings of notes to addresses.

Kevin

Permalink Leave a Comment

The Real Price of Internet Advertising?

October 2, 2015 at 9:19 am (internet) (, , , , )

I’ve been following some of the discussions about ad-blocking with interest.  I’ve now seen a number of comments from a range of sides on this one and am continually being surprised by some of the attitudes and opinions starting to appear in this arms race between blockers and advertisers.

Some of the facts and opinions that have surfaced that surprised me are:

  • Advertisers can buy their way out of ad-blocking.  So are advertisers now having to pay twice to advertise?  Kind of.  Or are ad-blockers positioning themselves as ‘guardians of the web’.  Kind of that too.
  • Blocking ads hurts the small people more than the big people.  Small businesses or creators or hobbyist event organisers and so on are the people losing out with ad-blockers.  The large providers will probably ride over much of this (or pay their way out) but these are the people whose enterprises (commercial or personal) are being enabled by the global reach and scale of the Internet, but it may all become fully cost ineffective if cheap, simple, high-reach advertising channels disappear.
  • Some websites are actively degrading their user experience for visitors using ad blockers.  The Washington Post apparently has experimented with not allowing articles to be viewed if you turn off ads.  And Google was removing ‘skip ad’ options for viewers of YouTube videos running Adblock Plus.

Why do people use ad blockers?  Well I suspect that many don’t mind adverts in the more general sense.  I’d say Ad blockers are arguably a blunt instrument deployed against anti-social, exploitative and intrusive adverts.

I regular get annoyed with in-your-face popups in front of an article I’m trying to read.  Is this a design failure on the part of the site to catch my attention by more subtle means?  Is it taking advantage of a captive audience?  Not sure., but that is a good reason for ad-blocking if the industry can’t regulate itself better.  And the drive for more intrusive ads is increasing – especially with more automatically playing video ads and the like on mobiles.  It is not want you want or when you want it.  End of.  That does not win friends or makes people warm to your products.  Maybe it is time for more obvious ‘commercial breaks’ in Internet use rather than a constant drip-feed of annoyance.

I also find it insulting when ads are designed to trick and fool you into clicking.  Whether that is placing link buttons right next to close X icons, especially successful on small screens I assume.  Or the plethora of ads that include the words ‘download’ as very visible buttons when you are attempting to download a document or software from sites such as sourceforge. Or maybe it is just in the general placing of ads so as to maximise accidental clicking. If the revenue is based on trickery, subversion and relies on accidental clicking/swiping/selecting to survive … then that is an industry in trouble indeed.

But the major reason right now for utilising ad blocking for me is as a defence against malware.  I regular read the detailed analysis published by a range of security vendors on how they’ve uncovered a complex malware serving system taking advantage of some of the large-scale advertising networks.  The bidding and auctioning processes for serving ads, coupled with many levels of redirection and URL shortening, and linked with content-delivery networks, not to mention links off to marketing and tracking databases, has created such a complex set of third party dependences for even the most trustworthy of websites that no place seems safe anymore.  Yes, you patch, keep plug-ins up to date, run AV checks, but it must surely be impossible to keep a PC clean of unwanted software these days and a major vulnerability is exposure to ads on sites you use and trust everyday.

Do I mind about the tracking?  Well again it depends. If done sensitively, then why not – there are benefits to seeing things of interest.  But I have no faith in such a lucrative business acting in the interests of us, their users – their ‘product’.  We have not opted-in to the use of free services in exchange for privacy – at best it is a false-choice due to the overwhelming network effects and dominant positioning of the large Internet companies.  We all know they are very good at staying below the ‘creepy line’ in knowing about you and providing just enough usefulness to keep us hooked to their services.  But with more hooking up between online services and offline data brokers, and not even thinking about any kind of future Internet of connected sensing and data gathering devices, things only look like getting worse before they get better.

So whilst the ad blocking war continues, being played out as a warning of the end of free services for consumers if they all block ads – I think the real win situation can only be when some of the above are fixed – lose intrusive ads, keep consumers in control of when they click or not and not trick them, ensure ad networks can not compromise trusted websites, and support responsible tracking of consumers with real opt-in.

I think only then will the need for ad-blockers go away.  I don’t think ad blockers have ever really been about blocking advertising – they have always been about maintaining control over the exploitation of a consumer’s Internet experience.  And for that, they serve more the purpose of an anti-virus, pop-up blocking, privacy supporting, malware-prevention, PC cleaning tool to me.

And in a world where people still fall for telephone ‘Microsoft support scams’, still install rogue Facebook applications in the hope of gaining a Dislike button, and still believe they can change the world via a status update (or at least think it will keep their Facebook data being sold off or made public), the need for protection like this shows no sign of going away just yet.

Kevin

Permalink Leave a Comment

icStation 4x4x4 LED Cube Shield for Arduino – Reprise

August 18, 2015 at 9:26 pm (computers) (, , )

I’ve been playing a little more with my icStation 4x4x4 LED Cube Shield (I described the details of the build and my code previously).  First, a little hardware mod.

Eventually I’d like to use this with some kind of network connectivity and most of the add-ons I have utilise the UART on pins 0 and 1, so I wanted to free these up from being used on the shield.  Thankfully this was fairly straight forward – I simply removed the connecting pins from the shield for pins 0 and 1 and re-patched them across to pins 9 and 10.  (I avoided pin 8 as this too is used with one of the radios I might use, the Ciseco SRF modules, in the future)

This means that the pin definitions in my code now look something like this:

int HC595_clockPin=9;   // SH_CP of 74HC595 
int HC595_latchPin=10;  // ST_CP of 74HC595 
int HC595_dataPin=3;    // DS of 74HC595 
int HC595_enablePin=2;  // Not OE of 74HC595
int LED_Pin16= 4;
int LED_Pin17= 5;
int LED_Pin18= 6;
int LED_Pin19= 7;

You can see this simple mod in the pictures below.

icstation4x4x4-nouarthack

The other change I wanted to make was to make the cube more easily programmable, rather than just loading in pre-set patterns, and to make the refreshing of the cube more independent of the main code.

To do the former, I added a few functions to set and clear the appropriate bits in an array that I can simply load into the cube when convenient.

unsigned int display[4];

void setpixel (int x, int y, int z) {
  // z defines the plane
  // within the plane, x + y*4 defines the bit
  display[z] = display[z] | (1<<(x+y*4)); 
}

void clrpixel (int x, int y, int z) {
  display[z] = display[z] & (~(1<<(x+y*4))); 
}

void clrdisplay () {
  display[0] = 0;
  display[1] = 0;
  display[2] = 0;
  display[3] = 0;
}

To improve the scanning of the cube, I decided to use the hardware timer interrupt available on timer 1 in the arduino.  After initially thinking about setting the registers directly, I decided the TimerOne library is actually so simple to use, I may as well just use that – so I did.

To initialise the timer:

// Use Timer1 on the Ardunio to trigger the update scan in the background 
Timer1.initialize(1000);
Timer1.attachInterrupt (ics444_display_scan);

And the scan routine looks like this:

int ics444_scan_count=0;
void ics444_display_scan () {
  if (ics444_scan_count == 0) {
    digitalWrite(LED_Plane[0], HIGH);
    digitalWrite(LED_Plane[1], HIGH);
    digitalWrite(LED_Plane[2], HIGH);
    digitalWrite(LED_Plane[3], HIGH);
    write_74HC595 (HC595_display[0]);
    digitalWrite(LED_Plane[0], LOW);
    ics444_scan_count++;
  }
  else if (ics444_scan_count == 1) {
    digitalWrite(LED_Plane[0], HIGH);
    digitalWrite(LED_Plane[1], HIGH);
    digitalWrite(LED_Plane[2], HIGH);
    digitalWrite(LED_Plane[3], HIGH);
    write_74HC595 (HC595_display[1]);
    digitalWrite(LED_Plane[1], LOW);
    ics444_scan_count++;
  }
  else if (ics444_scan_count == 2) {
    digitalWrite(LED_Plane[0], HIGH);
    digitalWrite(LED_Plane[1], HIGH);
    digitalWrite(LED_Plane[2], HIGH);
    digitalWrite(LED_Plane[3], HIGH);
    write_74HC595 (HC595_display[2]);
    digitalWrite(LED_Plane[2], LOW);
    ics444_scan_count++;
  }
  else {  
    digitalWrite(LED_Plane[0], HIGH);
    digitalWrite(LED_Plane[1], HIGH);
    digitalWrite(LED_Plane[2], HIGH);
    digitalWrite(LED_Plane[3], HIGH);
    write_74HC595 (HC595_display[3]);
    digitalWrite(LED_Plane[3], LOW);
    ics444_scan_count = 0;
  }
}

Note that for each tick of the timer I display one plane then move onto the next one for the next tick. Initially I had it setting each plane in sequence, but then found I needed a short delay between each plane to actually allow the LEDs to illuminate without bleeding into each other, hence splitting it up. I also found that if I don’t pre-set all four planes to HIGH (i.e. turning them off) before selecting the pattern I wanted, I’d also get some bleeding of values across planes, hence the sequence: a) turn all planes off; write the 16 bits to the plane as data; turn on the plane to be illuminated; wait before doing the next plane.

This seems to create a nice scanning persistence of vision effect without having to worry about when to trigger the scanning from the main code.  The last bits of glue are something to update a buffer containing the pattern to display (stored in LED_Plane[0-3] in the above code) and pretty much the same code as before for the actual writing to the registers of the 74HC595.

One gotcha – I set all my icstation4x4x4 code into a separate cpp and header file, so when I tried to #include <TimeOne.h> in my .cpp file, I kept getting:

icstation4x4x4.cpp:1:22: fatal error: TimerOne.h: No such file or directory
 #include <TimerOne.h>

Which was starting to drive me crazy as I could see the library was installed correctly, etc. After some Googling, eventually searching for “Arduino use of libraries from other libraries” or something like that, I found out that the compiler won’t include paths to libraries unless they are included in the main sketch file.  Consequently to use <TimerOne.h> in my .cpp I also need to #include <TimerOne.h> in my main sketch file too.  A quirk of the “C++ but not quite C++” nature of the Arduino IDE I guess.

Full code for my icstation4x4x4 included below.  Note: This is not written to be particularly good code (I don’t use portable definitions for 16-bit values, and there is minimal error checking, etc – this is just my hacking about, not meant for real use anywhere – I might tidy I up one day – maybe).  If you want to do it all properly, I suggest you take a look at the rather fine library described here: https://arduinoplusplus.wordpress.com/2015/08/13/device-independent-control-for-led-cubes/

Kevin.

Main Sketch:

#include <TimerOne.h>
#include "icstation4x4x4.h"

unsigned int display[4];

void setpixel (int x, int y, int z) {
  // z defines the plane
  // within the plane, x + y*4 defines the bit
  display[z] = display[z] | (1<<(x+y*4)); 
}

void clrpixel (int x, int y, int z) {
  display[z] = display[z] & (~(1<<(x+y*4))); 
}

void clrdisplay () {
  display[0] = 0;
  display[1] = 0;
  display[2] = 0;
  display[3] = 0;
}

void setup() {
  // put your setup code here, to run once:
  ics444_setup();
}

int x=0;
int y=0;
int z=0;
void loop() {
  // put your main code here, to run repeatedly:
  clrdisplay();
  int i;
  for (i=0; i<32; i++)
  {
    setpixel (random(4), random(4), random(4));
  }
  ics444_display(&display[0]);
  delay (2000);
}

icstation4x4x4.cpp:

#include <TimerOne.h>
#include "icstation4x4x4.h"

// Note: Original shield was wired to use pins 0-7, plus GND and +5V.
//       This has been re-wired to use pins 9 and 10 instead of 0 and 1
//       in order to free up 0/1 (RX/TX) for use as a serial port and 8 for use
//       with the Ciseco SRF radios (0/1 is the serial connection to the
//       radio and 8 is the radio 'enable' pin).
//
int HC595_clockPin=9;   // SH_CP of 74HC595 
int HC595_latchPin=10;  // ST_CP of 74HC595 
int HC595_dataPin=3;    // DS of 74HC595 
int HC595_enablePin=2;  // Not OE of 74HC595
int LED_Pin16= 4;
int LED_Pin17= 5;
int LED_Pin18= 6;
int LED_Pin19= 7;
int LED_Plane[] = {LED_Pin16, LED_Pin17, LED_Pin18, LED_Pin19};
unsigned int HC595_display[4];

// Each line (8 bytes) is an entire cube, with two consecutive bytes per plane of LEDS,
// and 16 LEDS per plane. LEDs are encoded in the following order:
//    Lowest plane byte 1, lowest plane byte 2, second lowest plane 1, then 2,
//    second from top plane 1, then 2, highest plane 1, highest plane 2.
//
//    Each plane is encoded looking at the Arduino oriented with the USB/power
//    designated by 'south' by started 'north west' as follows:
//        D0    D1    D2    D3
//        D4    D5    D6    D7
//        D8    D9    D10   D11
//        D12   D13   D14   D15
//
//        D16   D17   D18   D19
//          (USB)      (Power)
//    With D16 being the lowest plane, through to D19 being the highest plane
//    Of course, if you wire the planes up differently, that is up to you!
//
//    Each two bytes of the pattern are therefore:
//        B00000000, B00000000 -> D0-7, D8-15
//    with D0 = msb of the first value, D7 being the lsb of the first value,
//    and  D8 = msb of the second value, D15 being the lsb of the second value.
//
//    So the entire pattern is:
//    B10010000,B00001001,B00000000,B00000000,B00000000,B00000000,B10010000,B00001001,
//     |      |  |     ||                                          |      |  |     ||
//     |      |  |     |\ D15 bottom plane                         |      |  |     |\ D15 top plane
//     |      |  |     \ D14 bottom plane                          |      |  |     \ D14 top plane
//     |      |  \ D8 bottom plane                                 |      |  \ D8 top plane
//     |      \ D7 bottom plane                                    |      \ D7 top plane
//     \ D0 bottom plane                                           \ D0 top plane
//
// Comment following in or out to switch patterns in or out
//#define SWAP   1
//#define SNAKE  1
//#define BURST  1
//#define SPIRAL 1
//#define ALT    1
unsigned char pattern[] = {
  B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
#ifdef SWAP
  B10010000,B00001001,B00000000,B00000000,B00000000,B00000000,B10010000,B00001001,
  B00000000,B00000000,B10010000,B00001001,B10010000,B00001001,B00000000,B00000000,
  B00000000,B00000000,B01100000,B00000110,B01100000,B00000110,B00000000,B00000000,
  B01100000,B00000110,B00000000,B00000000,B00000000,B00000000,B01100000,B00000110,
  B00001001,B10010000,B00000000,B00000000,B00000000,B00000000,B00001001,B10010000,
  B00000000,B00000000,B00001001,B10010000,B00001001,B10010000,B00000000,B00000000,
  B00000000,B00000000,B00000110,B01100000,B00000110,B01100000,B00000000,B00000000,
  B00000110,B01100000,B00000000,B00000000,B00000000,B00000000,B00000110,B01100000,
#endif
#ifdef SNAKE
  B11001100,B00000000,B11001100,B00000000,B00000000,B00000000,B00000000,B00000000,
  B00000000,B00000000,B11001100,B00000000,B11001100,B00000000,B00000000,B00000000,
  B00000000,B00000000,B00000000,B00000000,B11001100,B00000000,B11001100,B00000000,
  B00000000,B00000000,B00000000,B00000000,B00001100,B11000000,B00001100,B11000000,
  B00000000,B00000000,B00000000,B00000000,B00000000,B11001100,B00000000,B11001100,
  B00000000,B00000000,B00000000,B00000000,B00000000,B01100110,B00000000,B01100110,
  B00000000,B00000000,B00000000,B00000000,B00000000,B00110011,B00000000,B00110011,
  B00000000,B00000000,B00000000,B00110011,B00000000,B00110011,B00000000,B00000000,
  B00000000,B00110011,B00000000,B00110011,B00000000,B00000000,B00000000,B00000000,
  B00000011,B00110000,B00000011,B00110000,B00000000,B00000000,B00000000,B00000000,
  B00110011,B00000000,B00110011,B00000000,B00000000,B00000000,B00000000,B00000000,
  B01100110,B00000000,B01100110,B00000000,B00000000,B00000000,B00000000,B00000000,
#endif
#ifdef BURST
  B00000000,B00000000,B00000110,B01100000,B00000110,B01100000,B00000000,B00000000,
  B00000110,B01100000,B01101001,B10010110,B01101001,B10010110,B00000110,B01100000,
  B01101001,B10010110,B10010000,B00001001,B10010000,B00001001,B01101001,B10010110,
  B10010000,B00001001,B00000000,B00000000,B00000000,B00000000,B10010000,B00001001,
  B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
#endif
#ifdef SPIRAL
  B11001100,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
  B01100110,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
  B00110011,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
  B00000011,B00110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
  B00000000,B00110011,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
  B00000000,B01100110,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
  B00000000,B11001100,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
  B00001100,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
  B11001100,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
  B00000000,B00000000,B11001100,B00000000,B00000000,B00000000,B00000000,B00000000,
  B00000000,B00000000,B01100110,B00000000,B00000000,B00000000,B00000000,B00000000,
  B00000000,B00000000,B00110011,B00000000,B00000000,B00000000,B00000000,B00000000,
  B00000000,B00000000,B00000011,B00110000,B00000000,B00000000,B00000000,B00000000,
  B00000000,B00000000,B00000000,B00110011,B00000000,B00000000,B00000000,B00000000,
  B00000000,B00000000,B00000000,B01100110,B00000000,B00000000,B00000000,B00000000,
  B00000000,B00000000,B00000000,B11001100,B00000000,B00000000,B00000000,B00000000,
  B00000000,B00000000,B00001100,B11000000,B00000000,B00000000,B00000000,B00000000,
  B00000000,B00000000,B11001100,B00000000,B00000000,B00000000,B00000000,B00000000,
  B00000000,B00000000,B00000000,B00000000,B11001100,B00000000,B00000000,B00000000,
  B00000000,B00000000,B00000000,B00000000,B01100110,B00000000,B00000000,B00000000,
  B00000000,B00000000,B00000000,B00000000,B00110011,B00000000,B00000000,B00000000,
  B00000000,B00000000,B00000000,B00000000,B00000011,B00110000,B00000000,B00000000,
  B00000000,B00000000,B00000000,B00000000,B00000000,B00110011,B00000000,B00000000,
  B00000000,B00000000,B00000000,B00000000,B00000000,B01100110,B00000000,B00000000,
  B00000000,B00000000,B00000000,B00000000,B00000000,B11001100,B00000000,B00000000,
  B00000000,B00000000,B00000000,B00000000,B00001100,B11000000,B00000000,B00000000,
  B00000000,B00000000,B00000000,B00000000,B11001100,B00000000,B00000000,B00000000,
  B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B11001100,B00000000,
  B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01100110,B00000000,
  B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110011,B00000000,
  B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000011,B00110000,
  B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110011,
  B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01100110,
  B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B11001100,
  B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001100,B11000000,
  B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B11001100,B00000000,
#endif
#ifdef ALT
  B11111001,B10011111,B10010000,B00001001,B10010000,B00001001,B11111001,B10011111,
  B00000110,B01100000,B01101001,B10010110,B01101001,B10010110,B00000110,B01100000,
  B00000000,B00000000,B00000110,B01100000,B00000110,B01100000,B00000000,B00000000,
  B00000110,B01100000,B01101001,B10010110,B01101001,B10010110,B00000110,B01100000,
#endif
};
int patternNumber=0;
int numPatterns=sizeof(pattern)/8;
int tickCount=0;
int tickCountMax=50;      // How many times to loop before changing the pattern
unsigned int currentPattern[4];

/*
  Protocol for sending the data to the hc595 is as follows:
   (see: http://www.arduino.cc/en/Tutorial/ShiftOut)
   
   "when the clock pin goes from low to high, the shift register
    reads the state of the data pin ... when the latch pin goes
    from low to high the sent data gets moved from the shift
    registers ... to the output pins"
   
   As we have two HC595s chained together, we use a 16 bit input value
*/
void write_74HC595 (unsigned int hc595value) { 
   digitalWrite(HC595_latchPin, LOW);   // ensures LEDs don't light whilst changing values
//   digitalWrite(HC595_enablePin, HIGH); // OE is negative logic
   
   // Shift each 8 bit value in sequence - the two chained HC595s automatically grab
   // the right bits - the first 8 to the first chip, second 8 to the second chip
   shiftOut(HC595_dataPin, HC595_clockPin, LSBFIRST, hc595value);  
   shiftOut(HC595_dataPin, HC595_clockPin, LSBFIRST, (hc595value >> 8));
   
   digitalWrite(HC595_latchPin, HIGH);  // data transferred from shift register to outputs when latch goes LOW->HIGH
//   digitalWrite(HC595_enablePin, LOW);  // re-enable (negative logic again)
}

/*
  Inputs: Array of 4 16-bit integers - one for each plane
*/
void ics444_display (unsigned int *pPattern) {
    HC595_display[0]=pPattern[0];
    HC595_display[1]=pPattern[1];
    HC595_display[2]=pPattern[2];
    HC595_display[3]=pPattern[3];
}

int ics444_scan_count=0;
void ics444_display_scan () {
  if (ics444_scan_count == 0) {
    digitalWrite(LED_Plane[0], HIGH);
    digitalWrite(LED_Plane[1], HIGH);
    digitalWrite(LED_Plane[2], HIGH);
    digitalWrite(LED_Plane[3], HIGH);
    write_74HC595 (HC595_display[0]);
    digitalWrite(LED_Plane[0], LOW);
    ics444_scan_count++;
  }
  else if (ics444_scan_count == 1) {
    digitalWrite(LED_Plane[0], HIGH);
    digitalWrite(LED_Plane[1], HIGH);
    digitalWrite(LED_Plane[2], HIGH);
    digitalWrite(LED_Plane[3], HIGH);
    write_74HC595 (HC595_display[1]);
    digitalWrite(LED_Plane[1], LOW);
    ics444_scan_count++;
  }
  else if (ics444_scan_count == 2) {
    digitalWrite(LED_Plane[0], HIGH);
    digitalWrite(LED_Plane[1], HIGH);
    digitalWrite(LED_Plane[2], HIGH);
    digitalWrite(LED_Plane[3], HIGH);
    write_74HC595 (HC595_display[2]);
    digitalWrite(LED_Plane[2], LOW);
    ics444_scan_count++;
  }
  else {  
    digitalWrite(LED_Plane[0], HIGH);
    digitalWrite(LED_Plane[1], HIGH);
    digitalWrite(LED_Plane[2], HIGH);
    digitalWrite(LED_Plane[3], HIGH);
    write_74HC595 (HC595_display[3]);
    digitalWrite(LED_Plane[3], LOW);
    ics444_scan_count = 0;
  }
}

/*
  Inputs: Array of 8 8-bit integers - two for each plane
*/
void ics444_displayBytes (byte *pPattern)
{
    unsigned int pattern[4];
    pattern[0] = pPattern[0]*256 + pPattern[1];
    pattern[1] = pPattern[2]*256 + pPattern[3];
    pattern[2] = pPattern[4]*256 + pPattern[5];
    pattern[3] = pPattern[6]*256 + pPattern[7];
    ics444_display (&pattern[0]);    
}

void ics444_setup() {
  // put your setup code here, to run once:
  pinMode( HC595_latchPin,  OUTPUT );
  pinMode( HC595_clockPin,  OUTPUT );
  pinMode( HC595_dataPin,   OUTPUT );
  pinMode( HC595_enablePin, OUTPUT );
  
  pinMode( LED_Pin16, OUTPUT );
  pinMode( LED_Pin17, OUTPUT );
  pinMode( LED_Pin18, OUTPUT );
  pinMode( LED_Pin19, OUTPUT );
  
  digitalWrite(LED_Pin16,HIGH);
  digitalWrite(LED_Pin17,HIGH);
  digitalWrite(LED_Pin18,HIGH);
  digitalWrite(LED_Pin19,HIGH);
//  digitalWrite(HC595_enablePin, LOW);  // Enable Not OE (negative logic)

  HC595_display[0]=0;
  HC595_display[1]=0;
  HC595_display[2]=0;
  HC595_display[3]=0;

  // Use Timer1 on the Ardunio to trigger the update scan in the background 
  Timer1.initialize(1000);
  Timer1.attachInterrupt (ics444_display_scan);

  patternNumber=0;
  tickCount = tickCountMax;
}

// To be called from the loop()
void ics444_demo ()
{
  int i;
  // only update it every tick otherwise just display as is
  tickCount--;
  if (tickCount <= 0)
  {
    tickCount = tickCountMax;
    for (i=0; i<4; i++)
    {
      currentPattern[i] = pattern[i*2 + patternNumber*8] * 256 + pattern[i*2 + 1 + patternNumber*8];
    }
    patternNumber++;
    if (patternNumber >= numPatterns)
    {
      patternNumber = 0;
    }
  }
  ics444_display(&currentPattern[0]);
}

icstation4x4x4.h:

#ifndef ICS444_H
#define ICS444_H
#include <arduino.h>

// To be called from the setup() routine
void ics444_setup(void);

// Perform one scan of the cube to display a complete pattern
//    Inputs: Four 16 bit integers, one for each plane of the cube
//    Order: Bottom plane to top plane, D0 to D15
void ics444_display (unsigned int *pPattern);

// As above, but takes the input as eight 8 bit values instead
// that is two per plane (ordered bottom to top once again)
void ics444_displayBytes (byte *pPattern);

// Displays the built-in patterns
// To be called from the loop() routine
// NB: Need to make sure the patterns are not commented out
//        in icstation4x4x4.cpp otherwise, none will be included
void ics444_demo (void);
#endif

Permalink Leave a Comment

Cheap Max7219 Chainable LED Matrix

August 13, 2015 at 10:53 pm (computers) (, , , , )

I can’t resist a cheap LED matrix, so when I stumbled across these 8×8 LED matrix displays with a Max7219 driver LED in this chainable form-factor for, get this, less than £1.50 each from electrodragon.com … well, I had to give them a go.  It is a relatively simple circuit board to build, so there are very minimal instructions, but there are still a couple of gotchas that might catch out a beginner, so I’ve put together these notes whilst putting them together.  By the way, I ordered 9 so I could eventually form a 24×24 LED square (3×3 of the matrices).

2015-08-07 13.06.582015-08-07 13.07.22

I started with the headers, then the discrete components, finally the chip.  The only thing to note is the polarity of the electrolytic capacitor (of course – look for the + on the circuit board) and the orientation of the chip itself.  Also note that ‘pin 1’ of the LED matrix sockets are indicated by a square pad in the top right of the circuit board (as seen from the top, with the writing the right way up).  It is worth fiddling with the electrolytic prior to soldering to try to ensure it doesn’t poke out over the top edge of the circuit board – although if it does, if physically mounting boards next to each other, it will quite happily overlap into the next board.

The design suggests that all the header pins face upwards and that the jumpers are used on the top of the board to chain them together.  however, I didn’t really want to have to take off the LED matrix every time I wanted to change how it was linked, so I opted to solder the connecting header pins to the underside of the board as shown.  It also gets around the issue they describe on the product webpage about the LED matrix not really fitting snugly on the board.  Mine fits nice and tight.

2015-08-07 17.44.28-sm

So all that remains is to add the LED matrix.  As I said, pin 1 should be indicated on the matrix itself and is indicated on the circuit board by the square pad near the electrolytic capacitor.

In terms of making the thing work, it is relatively simple to connect up:

  • CLK – D2
  • LD – D3
  • DIN – D4
  • VCC – VCC
  • GND – GND

Of course when chaining with jumpers DOUT goes to the next LED DIN.  The other pins pair up.

There is a lot of arduino code for these types of driver chips – start here – http://playground.arduino.cc/Main/LEDMatrix.

I used the code from here to test my setup – http://playground.arduino.cc/LEDMatrix/Max7219 – as written this assumes the same pinouts as I describe above (i.e. CLK, LD, DIN on digital pins 2, 3 and 4).

You just need to set the number of chained displays at the top:

int maxInUse = 9;

(in my case) and get to work playing.  The routines in the library provide a simple interface to setting rows on a single or all of the chained displays.  maxSingle is meant for when there is just one display.  maxAll displays the same value on all displays in the chain.  maxOne will target a specific display (starting with display number 1 up to your last – 9 in my case).

2015-08-08 16.02.16-sm

As you can perhaps see, this is using an Ardunio nano.  With 9 boards cascaded, getting the PC to recognise the nano was plugged in was sometimes a problem – it often gave me a ‘there is a problem with your USB device’ error on Windows 7.  It was fine with lesser numbers of matrices, so I guess there is a power issue with the nano struggling with the USB setup and initialising all 9 LED matrices at the same time.  Temporarily disconnecting VCC from the LEDs when plugging in the USB seems to solve the issue for me.

As I eventually want to be setting an entire row of LEDs in a larger grid, the maxOne function is a little wasteful as it has to shunt null values to all of the LED displays you are not targeting – so calling it 9 times means writing 81 bytes out across the DIN pin just to actually set 9 bytes.  Consequently it is possible to optimise it a little if you want to write an entire row to all displays in the same transaction.

Of course, if you refer back to the LedMatrix page, there are many other libraries that will do most of this for you, including Marco’s very complete library for scrolling text displays – http://parola.codeplex.com/ – but I quite like being able to see what the low-level code is actually doing to make things work.

I’ve therefore added a maxRow function as follows:

// Note: Sloppy code warning!
// There is no checking here that *col is an array of
// the correct length - i.e. maxInUse
//
// It should be defined and used as follows:
//    byte row[maxInUse];
//    // fill each byte of row with your data - row[0], row[1], row[2], etc.
//    // using one byte for each matrix in sequence
//    maxRow (1, &row[0]);
//
void maxRow (byte reg, byte *col) {
  int c=0;
  digitalWrite(load,LOW);
  for (c=maxInUse; c>=1; c--) {
    putByte(reg);
    putByte(col[c-1]);
  }
  digitalWrite(load,LOW);
  digitalWrite(load,HIGH);
}

But I haven’t mentioned the absolutely best feature of these little boards yet.  And that is that they are almost exactly the same dimension as a 4-stud Lego brick.  This means it was trivial to make a simple enclosure to hold my 3×3 grid and the nano.

2015-08-10 21.12.11 2015-08-10 21.12.04

I now have a really cool game-of-life running on my 24×24 LED grid.  At this price, I have another 8 on order so I can take it to a 4×4 grid (with one spare).

Kevin

Permalink Leave a Comment

Next page »

Follow

Get every new post delivered to your Inbox.

Join 27 other followers