Blog

  • Musical training software

    So I created an online class for learning how to play the Tin Whistle. It’s a hobby I’ve had since the late 80’s.

    Anyway, To play this instrument, when you want to learn new songs, there are fingering diagrams. These diagrams tell you which holes in the instrument to cover in order to get the desired note.

    So in order to improve the diagrams, I conceived a small, web based system.

    Examples here: My channel.

    The system is browser based, uses JSON to describe the tune to be played, and actually plays the tune (sound) and at the same time, shows you the proper fingering in order to play the same note on the tin whistle.

    I’ve found that the vast majority of people can’t read the musical notation so my solution only shows the fingerings and not the sheet music.

    The code, written in Javascript and JSON that does several things:

    1) Draws the instrument using SVG
    2) Begins playing the tune at a tempo determined by the JSON instructions
    3) Changes the fingering pattern to one that matches the currently played note.

    I built this automation rather than just shooting a video of me playing for a few reasons:

    1) The diagrams are standard and worthwhile knowing for tin whistle music.
    2) The code can easily be modified for most other instruments.
    3) It reduced my production time by 80% vs. using Synfig motion graphics.

    In addition, I built a spreadsheet that makes encoding new tunes merely a matter of listing the letter of the note and the duration (Quarter, half, eighth etc). The spreadsheet even has a calculation that “writes” the JSON needed to feed into the Javascript.

    Irish tunes are generally short, maybe 1 minute to play. It takes about 3-5 minutes to encode a new song and another few to capture and post the video. Let’s say 10 minutes total.


    The technical challenges:

    The sound capability built into Javascript was a bit difficult to get under control. There are a few concepts that have to be learned, more about audio processing than coding.

    There are different components that provide different audio functions, and the process of creating a sound involved connecting the components. For instance, there are components for volume, sound generation (oscillator), and filtering. One has to initiate them, connect them in a prescribed manner, and adjust their parameters to get everything to work.

    One particularly annoying thing is that when you turn on a particular note , a clicking sound is always there. In order to make the clicking sound go away, you have to add a volume component that keeps the sound off and quickly ramps it up (and down) to avoid hearing the “click”.

    This constraint causes some additional challenges like when playing notes fast., the ramping duration is set in milliseconds but if you want to play a tune quickly and are playing a short note, the note’s duration will significantly be impacted by the ramping. Getting triplets to work was also a challange.

    Ugh, everything is easy until you try to make it work, right?

    I run the tempo of the tune by having a timer clicking off heartbeats and each note’s duration is set relative to that heartbeat. Some basic math is done to adjust the note duration to the chosen tempo.

    There are a few lookup tables. One to map a note to a frequency and one from note to fingering pattern.

    All in all, it’s a nice little tool to make me more productive at promoting my Tin Whistle classes on Udemy and my self-hosted platform (In progress)

  • Adding interrupt driven automation events

    So I now have the new version of the automation software working. I am having reliability problems with one of the Ardiuino locations and I’m not sure if it’s a hardware or software issue.

     

    However, theere is a need to not continually poll infrequent, and non sampling events. especially high frequency ones.

     

    To that, I am beginning to adapt both the arduino and the node software to allow irregular events to send data back to node. To be clear here, the Ardiuno is still operating in polled mode (The main loop checks), but on different frequencies, I am enabling the detection and subsequent sending of an event back to node when and if there is an imprtant change or condition.

     

    For example, a sump pump.

    The reality of the typical sump pump is that it runs maybe 10 seconds at a clip, I need to be checking every 3 seconds or so as to not miss a run.

     

    So, the arduino, will be coded to read the status and only when it is on, to send a message to node.

     

    Downstream (pun intended) I can look for the data and take action on a regular basis like send an email.

    For this, I want an Arduino to constantly monitor the pump, but only send in data when the running is detected.

    I am modifying the Arduino code to have several diferent frequencies of checking and, when each time for a given frequency codes, to call different functions related to that frequency.

    Each different function will have its’ own logic and, if detected, it will compose and send a message to node.

     

    In order to maintain my base set of arduino code, I will use compiler switches indicating which Arduino code I am compiling (Attic, garage, etc) and then both the function code and the call to it will be included/excluded.

     

    Node will pick up the unsolicited message and simply add it to the database for logging. It won’t look to remove it’s matching send message and then remove it from the queue.

  • Version 2.0 of Temperature monitoring system

    So now that I have self configuring software in the Arduino, spinning up a new set of sensors or adding digital pins to an existing one is relative simple. All I need to do is the electronics and wiring and to change a JSON array in Node.js and I am in business.

    My short term plans include monitoring the state of the garage doors, a sump pump running monitor a humidity sensor outside , and a smart irrigation ground moisture sensor.

    Later, I plan on adding the ability to control my garage doors, and to add a new piece of software that adds intelligence over the collected data.

    For example, if the sump pump running frequency passes a certain threshhold, I’d like the system to send me an alert via email.
    If my garage doors are left open after a certain time, I’d like them to close.

    In the future I’d like my system to interface with my thermostat to make even smarter decisions about running or not running. FOr example if the temperature upstairs is cool and downstairs is warm, just run the fan and not the compressor. I have lots of ideas but all are based on having good data.

    My new module will have functions for each different thing I want to have it do. The code will query the database and apply some fuzzy or not so fuzzy logic in order to take actions and then add the actions to the transmit queue.

  • Version 2.0 of my monitoring software

    So it was time to update the software.
    the previous version of my software was rather basic. I would send it a basic commaind using AT mode in Xbee and it would dump a delimited string holding each analog sensors’ value.

    No digital input, output or pulsewidth capability.
    No ability to poll at a different frequency.

    There were other limitations that had been bothering me for some time.

    It was time to modify bothe the arduino code and the node/js polling/database code.

    The new version has the following capabilities:
    Arduino
    Now, the arduino is not configured stastically by the local code, but instead configures itse;f based on the incoming message

    Support for all I/Omodes

    It now uses JSON to receive and send data
    It supports different read and write modes including average of 5 readings analog, digital pulse output and even specialty modes… one is coded to flip flop the direction of current for minimizing corrosion on buried probes

    Node:
    The communication is much more robust.
    I’m using a transmit Queue to send requests
    Supports multiple devices
    Supports each pun being polled at a different frequency
    Supports retries (30 second, 1.5 minutes then 2.5 minutes.
    Manages transmit failures gracefully
    Adds “UNIT” to the database for supporting multiple arduinos in the mix
    Polling as frequent as 10 minutes and as slow as 30 minutes.
    A rolling PAcket ID to avoid mis-identifying a failed packet .
    Found a BIG bug that was not using the proper time in replicating the data to the web

    Added the capability for each pin to have a unique function to run on the data. Currently used for scaling the returned value
    Support for C and F sensors using the above.

    Web
    I added support for the 6 new sensors

    The hard part?
    Getting the Queue functioning right
    So the code scans over each pin of each device and determines if it’s time to request the read or output. If it is, the details of the pin (pin number, type, Xbee address and other information are added to a transmit queue. A second process is looking at the Queue every 3 seconds to determine if any transmission needs to be performed. If so, it sends the JSON packet to the indicated device. If there is a transmission failure, the particular request’s next transmission request is postponed 30 seconds or one minute. If there is no failure, a request packet comes back in a few milliseconds. The returned packet is matched with a transmission request. The returned packet is added to the local database and the transmission request is removed from the queue. If after 4 tries and 2.5 minutes, if a given request is not received back, the packet is removed from the queue in order to not accumulate in the queue.

  • More temperature monitoring effort underway

    I am planning on getting a new roof this year. My house never had soffit vents installed. They are supposed to allow a natural airflow that will keep the attice cooler and cause less decay in the roof and shingles. Also, a cooler attic will make it easier to cool the house.

     

    My plan is to expand my temperature monitoring to include the attic. Once the summer os over, I can have the roof replaced and soffet vents installed, and then next summer, I can have comparative data to determing if the soffet vents make a difference.

    To do this, I will need to modify my way of collecting data. I’m planning on modifying my Arduino code to be more generic (as I have even further plans for more).

    My intent is to make code that , upon receiving a message configures the Arduino based on the message, and then reads or sets the outputs/inputs and returns the values as appropriate.

    My code will change to handle many Adruinos and poll each one on it’s own schedule. In addition, each reading will be able to be modified by a custom function allowing scaling, linearizing and other corrections that may be needed. In addition, the function could contain logic and other code that could react and do things like sending alerts, controlling other devices and more. For example, Imaging at the end of the day, the outside temperature is cooler than the inside, but, the thermostat is about to turn on the air conditioner. I can suppress the A/C run because the house will cool itself off anyway. I also plan on recording when major systems are running like the furnace, Hot water heater, Air conditioner and sump pump. I could for example, note when the sump pump is running and send an email once the frequency of running gets past a threshold so I can proactively take appropriate measures.

     

     

  • PVC water pipe freezing – A study of what it takes to break the pipe

    In the winter of 2017/18, I performed a careful study of what it takes to break a pvc water pipe through freezing.

    I created a series of 1 foot pipes and filled them with different amounts of water to see how much water it takes to break. A second set of pipes had 100% filled pipes but with differing concentrations of anti-freeze.

    I also tested a larger set of PVC in case size matters and poly black pipe to see how it fared.

    What I found out and subsequently learned was this:
    1) Only one pipe broke, and it did so on the first night. The 100% water filled pipe. I had a 90% filled which never broke and neither did any of the others

    2) A little anti-freeze goes a long way. My 100% filled, 10% concentration pipe did not break.

    3) Black poly pipe is tough

    4) The danger temperature is just above freezing. Progressively colder temperature does not create more bursting

    5) When water freezes, it reaches maximum expansion (minimum density) at just before freezing and then has a jump to a less expansion. A discontinuity.

    6) There are factors that cannot be easily tested and could still cause pipe breakage. Ground movement, rodents, leaks into pipes, pressure from above by heavy vehicles, defective pipe and more can all conspire to cause pipe breakage. These guidelines are not perfect.

    Here’s the summary video of my experiment.

  • Upcoming video: PVC pipe, what it takes to break pipes through freezing

    Over the winter or 2017/18, I performed a controlled study of what it takes to break PVC due to freezing.

    PVC piping is often used for pool pumps and lawn watering systems.

    I’m working on a video that explains the test and shows the assembly, monitoring and results.

    I’m actually quite surprised with the results and hope you will be too. I plan on posting the video in the next 2 weeks

  • Porting to Ubuntu Part 2

    My Port from a Windows laptop to Ubuntu has been rock solid. The low power, Netbook that I converted to Ubuntu has been rock steady and comes with the benefit of low power consumption. In addition, I’m using the same machine to act as a disk server and it’s been great too.

    I’m glad I made the move.

    A few things remain to make it more stable.

    1) I need to convert the device to a static IP
    2) I need to confirm the Node code restarts on a reboot.

    Otherwise, I’m super happy with the conversion of the platform.

  • Porting NodeJS from Windows to Linux

    Porting Problem Summary:
    Getting the right versions of node & serialport installed
    Uninstalling Node
    Getting the node.js program to run automatically
    Getting the program to not shutdown upon disconnect

    Changing the port designation
    Changing the code due to node.js version differences
    Changing the permissions to the USB port
    Make int he changes stick between reboots

     

     

    For 2 years now, I’ve been running my data collection server on a windows laptop. This machine has one significant flaw. There is no battery in the laptop and when we have a power glitch, the machine does not reboot. This has caused loss of data, sometimes for quite a while.

    Recently, I tried to boot my ancient tower PC that contained our 2 Tb backup drive. It was dead as a doornail. I suspect the power supply got hosed somewhere along the way. I generally keep the machine off but plugged and maybe it got hosed by a surge. In any case, I did not have a replacement power supply and it was time to kill the beastly machine anyway.

    Do, why not take the drive ot of the machine, and make it available as a NAS storage device? I have an old and unused/unloved toshiba netbook that I had configured as a chromebook but my son refused to use it due to the speed.

    I installed Ubuntu v16 on the box, and setup samba to share the USB connected “backup” drive on my (mostly) windows network in the house.

    I had a drive to USB adapter lying around along with an external power supply for the drive.  The install went ok with some learning curve on setting up samba, a USB device etc.

    Then came the fun for setting up Node.js
    So I used the standard Apt-get command and got node running. Then I installed npm. However, my IOT system requires the serialport package for talking to the zigbee device. I installed the latest version of serialport but the system was not running.

    How to get my code into the linux machine?
    I did not have an ftp server anywhere that I could either push or pull the code to the system. A bit og googling and I discovered sftp runs against Ubuntu. A bit more googleing and Discovered PUTTY has windows version of the utility.

    I could not remember the ftp command for changing the local directory for the source file (I think it’s lcd)
    Ok so I got the code up on the server and immediately it was not running and giving classically bad error messages. I first realized that the port designation from windows was irrelevant (COM6) and I needed the linux equivalent. I’m not a hard core Linux person so some googling led me to ttyUSB0. Next, I was getting an error after changing that and after a little though and some understanding of Unix permissions, thought it could be permissions, and do changed the Port permissions to 666. That solved the serioal port issues I was having

    My first challenge was in finding the name of the serial port in Linux as m

  • IoT project – added robustness trial by fire

    Well only a few days after putting my latest version up, the system was tested in a very real way.

    A large winter thunderstorm moved through New Jersey on Wednesday night. One bolt of lightning made my wife and I jump out of our seats with a noise inside our home.

    It was so scary that I looked around the house to make sure nothing was on fire.

    Later that evening, I  noticed that my WIFI was down. A quick troubleshoot had me rebooting the cable modem as it was blinking all light in synch. The next morning it was the same and basically, most of the day was spent either on the telephone with tech support or driving to get a replacement cable modem.

    It got fried. Best I can tell it was the Ethernet ports in the Modem.

    Anyway, once I got that back online, I was then able to plug in  my wireless router and low and behold, it was not obtaining an IP address. So I’m assuming it got damaged as well (being attached to the same ports that got hosed).

    So I checked the Internet of Things gradient temperature project to see how it was responding. I was worried on two fronts. one was losing internet connectivity and the other was the surge put the Arduino or my logging computer into a non functional state.

    The whole system kept working without a hiccup. Before the Wifi situation was fixed, it had logged over 1,000 readings to the SQLite database and was gracefully failing on attempting to replicate them to the web based database.

     

    Here’s a screenshot of my local SQLite database table containing the non-replicated data.

    iotreplication

    Real world test # 1 passed. Connectivity outage did not take my application out.

     

    The replication is designed to do 9 updates every 10 minutes. I left a safety boundary around the time that reading are taken and written to the SQLite database due to file locking concerns. (I did not look into how SQLite handles locking if at all). Put another way, it updates 1.5 hours of readings every 10 minutes.

    The data is about 1.5 days stale and should be up to date in about 4 hours.