Brown noise sleep machine

Here’s my fantabulous sleep machine, so far:

brown

I haven’t finished painting it, squaring it off, or adding some mesh to protect the speakers.

As a first step, let’s build a white noise generator. You can find electrical circuits online (or here) to do just that. I opted for something simpler: using a MCU (microcontroller) to generate random on-off signals to generate the white noise. I used an ATTiny85 in my circuit, which is a nice, cheap MCU. It is overkill for the task, but the chips are cheap, and it is what I had available. An Arduino Uno would be excessive overkill for the project, but you can use it if you want to experiment. I found RS Components to be a great supplier, where the chips cost about £1. You could use cheaper chips like the ATTiny45. The 85 cost just a little more than the 45, but will give you more breathing space for your projects. Really, most chips will be up to the task for what this project needs it for.

The code for the Arduino IDE is as follows:

const int SPK = PB1;// Pin 6
void setup() {
  pinMode(SPK, OUTPUT);
}

void loop() {
  digitalWrite(SPK, random(2));
}

The code is so simple that you should not have any problem adapting it to your MCU.

Here is the schematic:

white_schem

Here are the components I used:

  • R1: 100K ohm potentiometer. This was really too much for what I wanted. I would recommend that you try to 1K pot, and see how that suits you. If the volume is still too loud, then maybe try a 10K pot. If the volume is too low, then try a lower pot.
  • D1: 1N4148 diode. This is a pretty common diode. Many diodes are likely to be suitable. At a pinch, you can omit the diode, but I advise you to use one if you have one. It acts as a flyback, a protective measure to against voltage spikes caused by inductive loads, in this case the speaker.
  • SPK: 4 ohm 5W speaker. This is quite large, and probably overkill. Just use whatever speaker you have at hand.

Instead of sticking slavishly to my specs, feel free to experiment. There is considerable scope for using other components. Do not over-fuss your design at this stage, because producing Brown noise will change it.

Note that I have used 5V as input. You might feel happier using 3.3V, but note that it will affect you choice of potentiometer and maybe speaker. Although the specs for the ATTiny85 say that it takes 3.3V input, I found that it was 5V tolerant. You have to be careful with voltages going in an out, as it possible to wreck the chip if you do things in a bad way. The ’85 was perfectly happy with my particular setup, though. I have accidentally abused ’85 chips in the past, and they have shown themselves to be quite robust little chips.

White noise has equal intensity at equal frequencies (Wikipedia). This sounds tinny and harsh to humans. The problem is due to the high frequencies. In order to produce a more pleasant sound, we need to attenuate those high frequencies. This is called a “low pass filter”.

Fortunately, there is a very easy way to do this: add a capacitor. We won’t produce the exact Brown Noise frequency response, but our results will be perfectly adequate for our purposes. We have thus created an RC circuit. A schematic of the intensity output of a resistor-capacitor at a given frequency looks something like this:

lpf

Compare this with proper Brown noise (as might be generated by Audacity):

brown-freq-audacity

Our modified circuit looks as follows:

brown_schem

It is basically the same setup, except that an electrolytic capacitor C1 has been added. I found that 100uF to be suitable. If the output sounds too tinny, which I think is unlikely, then increase the capacitance.

As you increase the capacitance, the output volume will go down. So you might try experimenting with a lower capacitance and potentiometer.

I hope you found this article useful and get a good night sleep as a result.

Update: This post is being discussed on Reddit.

Advertisements
Posted in Uncategorized | Leave a comment

Absolute Linux: first impressions

Being bored with Ubuntu, I decided to have a go at Absolute Linux , herein after referred to as Abs.

Abs is based on Slackware Current, with releases every couple of months. Abs is designed for older PCs, for which mine definitely qualify. I am a fan of fast systems in any event, and would consider using them over more bloated systems whatever the age of my machine.

Abs comes with the IceWm Window Manager. No other Window Managers are included, apart from the twm fallback. I am using a 1080p TV screen to test the WM, instead of a proper monitor, so I expect my screen to look worse than it would on a nice monitor. My past experience with IceWm is that it is fast, but with a ghastly mid-90’s look and feel. I was pleasantly surprised. Presumably Abs has done some customisation.

It’s not a pretty WM, but it’s not an eyesore. It is a fast one, though. Abs has added a default background which is grey, with text saying “Absolute Linux”. My verdict on this is: great! It’s simple, and unobtrusive, exactly how a desktop background should be. It there’s any Abs distro developer out there: do not change the background, perfection has been achieved!

The developers have eschewed gradients and fancy colour schemes. I hate gradients anyway, as they can look a bit naff if the rendering isn’t perfect. Colour schemes are also difficult to get right, and the team have actually got it right by not trying too hard to be fancy.

There are a few other desktop backgrounds to choose from, but I preferred the default. You can also choose a solid background colour if you like. What I do is have the default background for a regular user, and a red background for root.

Actually, there’s a neat trick here. I login in as a regular user using the login manager. In a separate virtual console I log in as root, and type “startx” to get a root X Windows session. I can flip backwards and forwards between the two sessesions using Ctl-Alt-F7 and F8.

Logging in as root is frowned upon, of course, but I think it’s OK for the first few times to get the box configured properly.

So far, I have concluded that Icewm is a good choice of WM. It even auto-mounts disks that are inserted. It’s nice, lightweight and doesn’t lack any important features. Except areosnap, which I think that all WMs should do.

I have two X Windows sessions going, including Chromium, and the system is using up 383M of memory. Good!

The thing I like about Abs over Slackware is that it has more up-to-date software. Yeah, I know Slackware users should be more concerned about stability over shiny shiny, but having said that, I have noticed that more recent software tends to have a better polish to it and is a little easier to use. I also like the latest version of GCC for development purposes, so there’s that.

I would argue that Slackware stable is too old, in general. Maybe it’s OK if you want to use it as a server where you never need to change anything, but for most people, something that is not as ancient is a much more sensible option.

Abs users can also make use of sbopkg, which is a boon.

Where Abs lets itself down compared to Slackware is it does not include Thunderbird mail, tmux or vim. I have compiled tmux and vim fairly easily. Still, I think they should be available out of the box.

Abs does have Chromium, which is OK, but I hate the fact that it doesn’t have a  more conventional menu and bookmarking system. Abs also includes a web browser called Falkon, which follows conventional desktop conventions, and I am more inclined to use. It also uses DuckDuckGo as a search engine, which I am increasingly favouring over Google for privacy reasons.

Youtube works out-of-the-box with both browsers, which is great to see.

I have tried Slackware Current a couple of times in the past. I failed to install it once. On another occasion I had a couple of things I wasn’t happy about. So I think Abs is a good distro to try if you like the principles of Slackware, think that the stable branch is way too old, and want a more polished version of Current.

Abs is obviously lighter in weight than Ubuntu with its bloated GNOME stuff, but has far less in the way of software. My main computer is Ubuntu 19.04 running LXDE as a WM. I have grown not to hate GNOME too much, although its resource utilisation is something I am unhappy with.

I like Slackware’s init system, too. It’s very easy to understand and configure. In other words, not systemd, which seems more hassle than it’s worth, in my opinion.

Anyway, make of that what you will. If I make sufficient progress on my test machine, then I might consider ousting Ubuntu from my main PC. We shall see. It has to be said, though, that Ubuntu is a pretty good distro despite its negatives.

 

 

Posted in Uncategorized | Leave a comment

A personal message

It seemed an opportune to write this post. It is aimed at the people who knew me personally, from the Glasgow Caledonian University days, rather than for general consumption. I decided to write it because there was talk of a get-together at Glasgow. Also, David made contact with me recently.

It’s probably not wise to divulge too much information on a public forum, but here goes anyway …

As you all know, I was frequently taking the mickey out of the university, and several people there. If I had caused offence, then I apologise to the people concerned. Most of it was meant in jest, but some of it overstepped the line. My treatment of Arlene was particularly uncalled-for. Looking back, I must have seemed like a bit of a tearaway. To quote Mark Sinclair, “we’ve created a monster.”

I am a man with particularly underdeveloped social skills, so I hope that you will all forgive me for my misdemeanours. Despite all my snide put-downs, I want you to know that my time at the university was very special to me, and something I look back on in fondness.

I also treasured the gifts that you gave me when I left the university. I know that they were a little joke on your part about how much I berated the university, but they did mean a lot to me. I still have the hat, and use it frequently; not now that it’s summer of course, but in the winter, for sure.

I used the mug regularly, mostly at work. Unfortunately, it eventually broke, although I did get a solid decade’s worth of use out of it. I was so attached to that mug I decided to get another. Unfortunately the replacement was rather flimsy, and broke within a few weeks. Alas, the quality of their merchandise fell short of my expectations from such an august institution. Cough.

If anyone knows how to pass this post onto Jagan, or indeed anyone else who may be interested in an update, then please do pass a link to this article along. I think that I hadn’t shown Jagan enough appreciation for his supervision on my thesis. If you’re reading this Jagan, then I thank you, and hope I wasn’t too much of a handful to deal with.

I value you all. I had a great time. I wouldn’t necessarily want to repeat it, but it was great nonetheless. It is of course David that I formed the deepest bond with. I consider myself lucky to have him as such a close friend, even though contact has waned over time.

Ah, nostalgia ain’t what it used to be.

If any of you want to chat with me personally, then feel free to do so. If you want some kind of collective “Question and Answer” session, then maybe we could do something like that, too.

Many of you have gone on to achieve distinguished careers, becoming professors, heads of departments, hedge fund bigwigs, and so on. My life is rather more humble, however. I joined an outfit called IQ Financial in the early 2000’s. They were bulking up in staff in anticipation of a big sale. That sale never materialised, so they made a complete about-turn.

I was laid off after only being there for about a month. I moved back in with my folks up in Scotland. I found a job in 2002 at a company called Smith Rea. It was an Oil & Gas consultancy. I secured the position because of Russell, a friend I had made whilst at Sheffield University. I owe him an enormous debt of gratitude, and like David, he is a very close friend. I do not make many friends, but of the friends I do make, the friendship runs deep.

Smith Rea was acquired by Intertek, a big UK company, and a constituent in the Footsie. They basically bought out Smith Rea at its peak. A few years later the price of oil declined, and they ceased many of their operations in that sector, and of course ousted staff in the process.

That was in 2015. Although no-one said it, I knew that I was not an especially valuable employee of the company. I had not lived up to the potential that they expected of me. So I was one of the first out the door, at a time that they considered that their Aberdeen operation might still be viable.

I had always figured that Intertek would be the last job I would ever have. That assumption has, so far at least, turned out to be true. A programmer in his 50’s does not stand much chance.

It has given me time to pursue my own interests at any rate, even if those interests have only amounted to staring at the internet.

I started some hobby projects in programming. Most recently, I have been interested in mcus (microcontrollers). These are tiny “computers”, but with only a fraction of the power than the ones that drive your typical desktop PC.  They are typically used to control electronics. I have made a few devices. They can be fun to program, but also frustrating at times. It’s great to be able to create a little device that can be run off of a coin cell battery, though.

I’ve also got into doing some exercise on a regular basis. Nothing fancy, just some cardio, flexibility stuff, and some running. I’ve done a few “parkruns.” These are free public group runs held each Saturday. It’s become a world-wide phenomenon. My local parkrun is quite a long way away, so it’s not something I go to often. The rest of my runs are out and about the countryside where I live. I am happy with my progress, and think I’m doing quite well.

Well, that’s about it for now. I hope you have all been keeping well.

Although I cringe at the prospect, I have decided to attach a pic. Alas, time has not been kind to me. I’m wearing my Glasgow Caledonian hat event though it’s summer; because, well, it somehow seems appropriate to the occasion.

2019-08-04-093332.jpg

Take care, one and all.

Posted in Uncategorized | Leave a comment

Pics of #Aberdeenshire

These pictures were taken today, despite being date-stamped 2015. Glorious weather and scenery.

 

Posted in Uncategorized | 1 Comment

Gauging button bounce on an #esp32 using atlast forth

I thought I’d try to get some kind of handle as to how much a button is bouncing around. Here’s the code:

23 input_pullup pinm
variable count
: ++ dup @ 1+ swap ! ;
: 0count 0 count ! ;
: igo 23 digr v0 @ <> if count ++   1 v0 @ - v0 ! then ;
: go 0count begin  igo     key? until count @ . ;
go

It counts the number of times the value of the button on pin 23 changes. Enter “go” on the serial port, press the button down, then release. Then hit the Return key to stop the loop and obtain a count of the number of times a change had been detected.

Most of the time it prints the value 2, which is the expected answer. Occasionally it will print 4 or 8. The highest value it reached was 10. So although my switch is pretty good, debouncing is still necessary.

 

Posted in Uncategorized | Leave a comment

#atlast #forthlang vs #micropython speed test on #esp32

A week or so ago I started out porting John Walker’s public domain Atlast Forth over to the Arduino. The code is highly portable, so who knows, maybe I’d get something going for the Uno, and maybe even the ATTiny85. Maybe.

I thought I’d do a little speed comparison to see if Atlast had any point at all to it. Micropython is an excellent and mature platform for microcontrollers, and is vastly superior to my own humble effort.

Anyway, do the speed test is to read a pin 20 times in a row and see how long it took.

The code on Micropython:

def fn():
    for i in range(20):
        switch.value()

That took 845us (microseconds).

Here’s the equivalent code using atlast:

: t 20 0 do 23 digr drop loop ;

Here’s the timing function:

: u usecs t usecs swap - . ;

That took 29us.

Wow.

Although my Forth is immature, and is quite inefficient in how it works, I am very happy about its speed relative to Micropython. So who knows, maybe it can add some value when Micropython is proving just a little too slow to be usable.

Happy programming.

Posted in Uncategorized | Leave a comment

Solving the #perl weekly challenge 6 in #racketlang

Seeings as I was playing with P6 (perl6), I thought I’d have a crack at the Perl Weekly Challenge #6. Here’s a recap of the first challenge:

Create a script which takes a list of numbers from command line and print the same in the compact form. For example, if you pass “1,2,3,4,9,10,14,15,16” then it should print the compact form like “1-4,9,10,14-16”.

I tried doing it in P6, but ran into a number of problems. In one attempt, I tried laying down delimiting markers. But P6 didn’t really seem to want to split my array the way I wanted. I also had problems creating arrays of arrays. Another odd problem was that P6 seemed to think that some of my arrays were read-only when I used them in curly braces. I found that to be totally unexpected. What also surprised me is that there does not seem to be a way to intersperse a value between elements in an array. It must exist, surely?

I am new to P6, of course, but the challenge gave me more difficulty than I expected. I eventually gave up on the P6 implementation, and switched to Racket:

#lang racket

(require srfi/13)

(define inputs '(1 2 3 4 9 10 14 15 16 18))

(define marked
  (let loop ((curr '()) (acc '()) (inputs inputs) (prev +inf.f))
    (if (empty? inputs)
        (cons curr acc)
        (let* ((el (car inputs))
               (rem (cdr inputs)))
          (if (empty? curr)
              (loop (cons el el) acc rem el)
              (if (= el (+ 1 prev))
                  (loop (cons (car curr) el) acc rem el)
                  (loop (cons el el) (cons curr acc) rem el)))))))                       

(define seqs
  (map (lambda (x)
         (let* ((el1 (car x))
                (el2 (cdr x))
                (diff (- el2 el1)))
           (case diff
             ((0) (number->string el1))
             ((1) (format "~a,~a" el1 el2))
             (else (format "~a-~a" el1 el2)))))
       marked))

(string-concatenate (add-between (reverse seqs) ","))                                           

I am not expert on Scheme, but at least I found a solution. I wonder what other solutions are like.

It is entirely possible that a P6 implementation would look a lot better than a Scheme implementation. I tend to dislike recursive constructs, but I think that in the case of the challenge presented, recursion works well. If I were to attempt a P6 implementation again, I think I would try to “transpile” the Scheme version.

I am not saying that Scheme is better, but forcing me to write in a recursive style seemed to make me uncover a correct solution. From what I can gather, P6 does not support TCO (Tail Call Optimisation), so it’s likely to be a memory hog on large arrays.

Posted in Uncategorized | Leave a comment