Sunday 27 December 2020

A rant about measuring CO2, temp and humidity with Arduino

Before Christmas, I had a look at a couple of CO2 sensors and was surprised to see how unnecessarily complex our life is made. At which point did someone decide that the best way to check the value is to do it through an app in your mobile and not through a simple screen on the device? Honestly, I was also quite surprised at the prices. 150 euros reduced from 210 euros? Electronic components are quite cheap, so either high quality sensors are very expensive or someone is making a lot of profit (or both). Maybe I could make one myself despite my very limited knowledge of electronics?


Anyway, since I already happen to have an arduino, a few Raspberry Pi´s and a Calliope Mini, I thought I may as well buy a few sensors and google my way through. The internet is full of successful examples so I thought it may be worth explaining where I struggled. Things never seem to be so straight forward for me. I remember watching one of the Star Wars films many years ago and how I smiled to myself when young Anakin built C-3PO as a pet project when he was ten years old. But then, he was a Jedi and I am not.

Jedi or not Jedi, I bought the following:

SSD1306 OLED mini screen => 6.50 euros

MQ135 gas sensor => 5 euros

DHT11 temp and humidity sensor => 4.50 euros

 

Except the MQ135, you can buy everything you need and a lot more for under 30 euros with a starter kit, with arduino breadboard, etc included.

I found this video, which seems to be what I wanted, except things are never so easy. After I did all the connections, installed the Arduino IDE, downloaded the Adafruit libraries mentioned in the video and typed the program I got a very blank screen. Not quite what I wanted but not totally unexpected either. Ok, so is it the sensor or the screen? Or both? The good news, time to go into a rabbit hole and learn about OLED´s, I2C addresses and more watching this great video from DroneBot Workshop.

Eventually I had a look at the webpage of the people selling the screen and noticed there was an Arduino library mentioned in the Downloads and Links section! I tried it and still got a blank screen. Looked like a dead end but I also noticed that there is a free ebook which comes with each component. I got the ebook and, surprise, surprise, they mention a different library, U8g2. Even with this one, I could not make it work with the template program provided. My screen is 128x64 but the way to instantiate the display provided in the book, U8G2_SSD1306_128X64_UNIVISION_F_HW_I2C, threw and error. However I managed to make it work using U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C (note the change from 128x64 to 128x32). That means I lose half the screen resolution, but since I only need to display three numbers, it is still ok.

At that point I could display some text, just not the values from the gas sensor. After a lot of looking around, I noticed that the connection to ground in the breadboard was in the wrong place. Once that was fixed, I got the CO2 reading! One small step in the right direction.

From the little I have learned so far, the sensor needs to be left connected for 24 hrs to burn in and then calibrated (read the actual value outside and adjust the reading to be the expected normal CO2 values of 350 to 450 ppm). The calibration can be done with quite some detail.  Right now I get a reading of 250 to 300 ppm. Since the accuracy of this sensor is not that great, it is probably best to go for a traffic light rather than actual values. Good if below 400, amber if below 800 and red otherwise. Not yet implemented, but I happen to have the ideal traffic light module which came as part of this 35 in 1 kit. Otherwise, there is a great opportunity for more rabbit holes, here and here for a start.

Enough of the gas sensor, what about the temperature and humidity sensor? That should be a lot easier, plus I do know which values to expect. Well, it turns out nothing is easy and straight forward. The reading right now is that I am sitting at home at 13 °C and 146% humidity (!). 

As by now was to be expected, there are differences between the connection instructions in the ebook and the datasheet, which actually mentions a pull-up resistor


Plus of course, who says there is only one type of DHT11 sensor? The eagle-eyed will have noticed that one has three pins and the other has 4 pins. The one included in the sensor kit happens to have 3 pins. And, never mind what the ebook says, it also mentions a pull-up resistor in the data sheet. In one place a 5.1K resistor is mentioned and in another a 10K resistor. Would this explain the wrong readings? I happen to have 10K resistors but no 5.1K ones. So the easiest thing is to try with the 10K first just to fins out that the readings are still wrong. Next is to put two 10K resistors in parallel and give it a try. Fingers crossed and, surprise, surprise, readings still wrong. In fact not temperature reading is -14 °C. Humidity has somewhat improved down to 148%.
 

I will keep prodding the internet and report back when and if I manage to get some decent temp and humidity readings. I have a suspicion that this has to do with the data transfer. One thing is for sure, the more you learn, the more you know that you don´t know.

UPDATE 28th December: so after some more reading about bus data transfer, trying to understand the data sheet and a few more youtube channels and even considering whether to redo the whole thing using a Calliope, I noticed that I had not initialized the temp sensor! So a simple dht.begin() did the trick! Temperature is within two degrees of the reading of an analog thermometer. Humidity currently showing 42%, which seems reasonable.

Friday 25 December 2020

Advent of Code 2020 (ii)

 


This year I managed to complete 43 of the 49 Advent of Code tasks (on Xmas day, i.e. today, you only get the 50th star if you have completed all previous 49 tasks). Really proud and happy that I participated every day for almost a full month because I have practised and learned a lot.

A few things that come to my mind:

  • I finally felt compelled to set up WSL2 on my laptop, which involved tweaking something on the bios. 
  • I cloned and tweaked a framework to keep some order on the solutions.
  • I used VS Code (instead of pycharm) and learned about passing arguments to the debugger.
  • I published my code to github, struggling with git commands from time to time (is there anyone who doesn´t??)
  • I googled my way through relative imports in python and vs code setup for projects, eventually dropping the framework in favour of a more simple solution.
  • Library of the month: Collections, I made heavy use of defaultdict, used Counter a few times and thought it was a pity that deque is O(n) for searches and not O(1).
  • Surprised I did not use pandas at all. Not surprised that I used networkx and numpy. I still need to get a hold on regular expressions though.
  • Got reasonably good at parsing files, however a colleague has suggested that I have a look at lark parser   
  • Found out that sadly John Conway passed away this last April.
  • Following another colleague´s advice, I borrowed Python Cookbook from our mini department library but only found time to go through first chapter. 
  • Chinese remainder theorem and Bézout's indentity
  • Needless to say I went into several rabbit holes.
  • Best rank position for Part 1: 1874 on Day 20, which ironically is one of the few days I didn´t manage to complete part 2.
  • Best rank position for Part 2: 2912 on Day 21
  • Quickest Part 1: 00:17:50 on Day 6 (but only rank ~6200)
  • Quickest Part 2: 00:33:40 also on Day 6 (but only rank ~6000)
  • Recurring issue: typing "for i in intVarName:" instead of "for i in range(intVarName)":
The whole experience was made even more enjoyable because a few colleagues joined a private leaderboard and a whatsapp group just for AoC, so this has been a running theme all this month (we were careful with spoilers, as not everyone was doing the puzzles at the same time).

I may try to finish the rest of the puzzles over the holidays. If you want to try AoC, you can join any time and do the puzzles at your own pace.

Friday 11 December 2020

Advent of Code 2020

For the second year running, I am giving a try to Advent of Code. Last year I got 18 stars in the first 10 days. So far, so good as this year I am already at 22 in the first 11 days, but I assume this is where it will get more tricky and I will run out of time (and more likely brain power) to solve the daily puzzles.

This year I did not get to do much coding at work, so this is like an end of year private treat to myself. Advent of Code is a superb learning experience and even if I am far away from the real pros, I think about it in the same way I do about running from time to time.

The one other thing that dawned on me is that I probably approach reading other people´s code as other people may approach reading poetry or sheet music.  



Sunday 8 November 2020

Estar como una regadera

 

Yo quería hacer una foto del pajarillo que alegremente desordenaba el montoncito de hojas de nuestra terraza y, sin darme cuenta, he pillado a las regaderas dándose un beso.

Saturday 7 November 2020

España vacía o la España vaciada

Suelo escuchar el podcast de la Cultureta, en el que suelen meterse con Sergio del Molino a cuenta de si se dice la España vacía o la España vaciada, aunque sospecho que en realidad es una forma de hacerle publicidad a su libro. En cualquier caso, entre esto y que esta semana llevo vistos tropecientos mil mapas de EEUU mientras acaban de contar los votos, he tenido la idea de hacer un mapa con las provincias de España coloreadas con su población hasta igualarlas (más o menos) con la de Madrid, que es la que tiene la mayor población de acuerdo con la Wikipedia. Hacerlo ha sido entretenido y, al revés de lo que suelo hacer, no ha requerido ni una sola línea de código. Hay veces que la opción low-tech es la mejor, por ejemplo coloreando este mapa que, eso sí, he encontrado mientras buscaba como hacer esto con python, que la cabra siempre tira al monte :-)



Sunday 1 November 2020

Calle Mayor


 Rescato una foto antigua de hace un par de años de la Calla Mayor con un puntito de nostalgia.

Sunday 20 September 2020

Desde mi jardín

 

Normalmente la etiqueta de cazadores cazados tiene otro significado, pero en este caso creo que es apropiado usarla.

Saturday 8 August 2020

Cracked Disc

I only have 5 or 6 discs. This one is cracked but I cannot get myself to dispose of it.

Friday 7 August 2020

WUGC Heilbronn 2000 - España

We played ten games that week, four from the initial round robin on Sunday and Monday, then on Tuesday we lost against Italy and won against Ireland, 13-15 on a really tight game. On Wednesday we lost against both Netherlands and Russia and then also against South Africa on Thursday. We played one final game on Saturday against Taiwan again, 15-6 for us. Of course I could not remember any of this twenty years later, but I found an old agenda in which I had scribbled the games and the results, hopefully they are accurate. (edit: Espiau pointed me to the scores)

In between games, there were also training sessions, not to forget the parties. All in all, although I was reasonably fit twenty years ago, by the end of the week I was so intensely tired that there is a photo of me sleeping while "watching" the final game in the "stadium" between USA and Sweden.
 
Team España
Albert, Curt, Eric, Gabriel, Kaleen, Óscar, María José, Miquel, Peter, Rocky, Sofía, Stratton, Tim, Tino, Ignacio, Luis Alberto, Francisco, Juan Carlos, José

After one of the games with Taiwan

Wednesday 5 August 2020

World Ultimate Frisbee Championship - Heilbronn 2000 - Opening Ceremony and Team España

Opening ceremony (and the day I first met my team mates!) was on August 5th. There was a tournament newsletter and they had an article featuring Team España a couple of days later!
 

07. August 2000 
Ultimate España
There is not a very long history of disc sports in Spain. Most Spaniards
think of a Frisbee as „that plastic thing you bring to the beach". When you
mention Ultimate as a sport, they say „Que?"
Though there are only about 70 ultimate players
currently playing in Spain, it seems that Spanish
Ultimate is finally getting off the ground. This is
the first year that a Spanish Team is competing at
a World level and players have come together
from Barcelona, Madrid, and Gran Canaria to
form the team.
The history of Spanish ultimate starts about 5
years ago when a group of people started playing
in Las Palmas de Gran Canaria, Canary Islands,
eventually taking the name of Pio Pio. Within 2
months they went to France to participate in the
European championships. But since then, only a
few players have been able to travel to tour-
naments - they are closer to Africa than they are
to mainland Spain. Still, over the years they've
continued to play with the spirit that typifies
Ultimate and have grown to approximately 15
players. They hosted their first beach hat
tournament in March 2000 which gave all the
Canary players a chance to play in a tournament
and left everybody else begging for it to be
repeated annually.
Independently, Barcelona's Patatas Bravas began
playing in the winter of 1998 when the Ultimate
gods conspired to bring several players together
who had all played in other places. After realizing
that nobody would get up before 1 pm on a week-
end, practices were moved to late afternoon and
Ultimate addicts were created. Since then,
the Patatas Bravas have participated in tour-
namets in Germany, France, Switzerland, Italy
and Portugal. The team currently has 25 players
and is comprised of "Catalan/Spanish and"
foreign players. I guess Ultimate is still a bit of a
beach thing in Spain because both Pio Pio and the
Bravas practice on the beach, bare foot, all the
time. The sun in Spain is great, but one of the
drawbacks is its effect on grass fields! The Bravas
also organize a beach hat tournament that was
first hosted in the fall of 1998 and has since
become the infamous last European Outdoor tour-
nament of the year. They're working on bringing in
more women and getting a juniors team started at
a local school to try to raise interest and ensure
that Ultimate will continue.
The internet age helped contribute to the for-
mation of Los Quijotes from Madrid. They began
playing in December of last year after several
requests came to the Bravas and Eurodisc mailing
lists requesting information about ultimate in
Madrid. With 6 names to start with, things
seemed to take off when Juan Carlos, a Madrileño
who learned to play ultimate while studying in
England, took charge of motivating and
organasing. They have not yet participated in any
tournaments and are still in the tenuous stages of
team creation since many members of the initial
group have moved out of Madrid, including Juan
Carlos. Hopefully things will keep moving and
we'll see more ultimate from them in the future.
Finally, and most recently, a team was started in
Tenerife, another of the Canary Islands. A lone
flying Italian initiated a university ultimate course
last spring in which a group of about 15 students
participated. The first real competition between
two Spanish teams has also evolved out of this
effort with the 2 Canary Island teams traveling to
play against each other a few times and a final
competition organized at the end of the course.
The University de La Laguna, where they also
have the luxury of grass fields, will offer a year-
long course again in the upcoming academic
year. It looks like a lot is happening quickly with
Ultimate in Tenerife!
The Spanish team at WUGC 2000 is comprised of
4 players from Gran Canaria, 1 player from
Madrid, and 14 players from Barcelona. With so
few players in the entire country, the selection
process essentially boiled down to those who
were interested, eligible, could afford it, and were
willing to commit to playing and having fun.
Maybe not the most stringent criteria, but hey, it's
a start! There are 3 women playing with the team
since there are not enough women (yet) to form a
mixed or women's team. Since this is the first time
Spain is participating, we really don't know what to
expect. Our main goal is to have as much fun as
possible and to play as hard as we can. Apart from
that, we want to find out what diving on the grass
is all about, see how fast we can run when not in
15 centimeters of sand, and see if it's possible to
avoid blisters with those cleats we're supposed to
wear. No matter what, we're all ready and really
excited to be here! Kaleen Moriarty, Team España

Tuesday 4 August 2020

WUGC Heilbronn 2000 - T-shirt

Some people exchanged T-shirts after the tournament with participants from other countries. I am glad I didn´t and kept mine.



Monday 3 August 2020

World Ultimate Frisbee Championship - Heilbronn 2000 (ii)

The tournament`s opening ceremony was in the afternoon of Saturday 5th August. Since I was living in the UK at the time, I somehow managed to join the British team on their trip which really simplified my travel arrangements. I drove to London on Friday evening, staying a few hours in the flat of a friend of a friend until we got on a taxi to Heathrow in the wee hours of Saturday. Once in Germany, someone had arranged a bus from the airport to Heilbronn.

Incidentally, this was the first time for me in Germany (except for a couple of airport transfers in Frankfurt en route to and from Moscow a few years earlier). Little I knew then that I would end up moving to Berlin the following year.

Regarding the seedings and the initial round robin schedule see below. Games were finished at 15 points or at a given time. On our first day, we managed to score just 2 points against GB, however one of points was by one of the women in our team, I cannot remember who. I remember though that someone in the British team got really annoyed about that. No idea about the score with Denmark in the afternoon.

For the second day, the then world champions, Canada, had an early training session with us (15-0) and then in the afternoon we finally managed to win a game, 7-15 against Taiwan. That was on Monday 7th August 2000.




Sunday 2 August 2020

World Ultimate Frisbee Championship - Heilbronn 2000

It´s now twenty years since WUCG 2000 in Heilbronn, the world ultimate frisbee championship in which Spain was participating for the first time (as far as I know). I was very lucky to be part of the Spanish team and have very fond memories of the whole experience.

I first played Ultimate frisbee in high school, which at the time was very unusual in Spain (and probably still is?). Then I didn´t play for many years until I went to England as an Erasmus student in 98. I joined a great group of people coached and led by Aaron Altmann, who was the soul of Alien Nation, the Ultimate frisbee team at Cranfield University. Back in Madrid the following year, I helped founding Los Quijotes in Madrid in mid/late 1999 while serving in the Air Force (conscription was still a thing back then), until I left for UK in early 2000 to work for Rolls-Royce. There was no team in Derby, so I joined a team from Nottingham, SuperFly. Then I moved to Berlin in late 2001 and joined Discipuli, one of teams training at TiB1848, with which I continued playing for a few years.

So this week will be a bit of a throwback, posting some memorabilia that I kept from WUGC 2000 all these years.





Wednesday 13 May 2020

Monday 11 May 2020

Squirrel (i)


This was the squirrel that was in the cat´s mind. But the photo was taken before I noticed the cat.

Sunday 10 May 2020

Black cat


There was a squirrel on the tree next to our balcony and I believe this cat had something in mind. I haven´t seen the squirrel again, but as long as it stayed high up, it should be fine.

Regarding the photo, the cat was in the shade and from quite a distance, so I had to push it up a bit with my very old 400D (already antique?). I ended up with 1/100 with 176mm, f4.5 at ISO 200 to balance noise, sharpness using a hand held tele and a min amount of light which could be post processed. The result is somewhat noisy, but look at those eyes...

Saturday 9 May 2020

Photos from my windows


You don´t have to travel far to take photos. Sometimes it´s enough if you look out of your window.

Tuesday 14 April 2020

Privacy-first explained with Calliopes


This was actually quite a bit of fun.

A few links that may be of interest:
- The comic is from Nicky Case
- DP-3T white paper and much more 
- Two of the calliopes are actually on temporary loan to CoderDojo Dahlem from the great guys at Calliope Mini
- The code was done using TigerJython4Kids, check their great page!

Saturday 11 April 2020

Serenity under the sun


We are playing a lot of badminton these days in the garden. And a lot of reading.

I didn't notice my daughter taking the photo while I was reading this book.

Sunday 29 March 2020

#BeingPartoftheSolution 2



Additional comments after a couple weeks into remote schooling.

File sharing: I got familiar with nextcloud, which offers a great amount of functionality such as typical file sharing services like Google Drive and MS OneDrive. Whatever system you use, I would separate communication in two flows:
- One direction, from teacher to students (release tasks and announcements), i.e. a public folder, most likely with subfolders for each subject as per the picture above.
- Private comms between each student and the teacher. This requires a password protected folder for each student.

Students and parents use different email providers, a 5MB file may be a problem for some, a 10MB may be a problem for many, a 100MB video will probably not work with most. Just sync a local folder with a cloud one and store there whatever is required for the students to pick it up.

Videocommunications: In these two weeks I have tried zoom a lot, discord, Jitsi, whatsapp and heard about MS Teams and whereby.com Zoom has many pros but one big con, privacy issues.
I have the feeling that the others have shortcomings when it comes to getting other people join (think elderly people, as my parents) and whatsapp is easy but it limits participants to just 4 people, plus many teachers may not want to disclose their private phone number for obvious reasons.
I am not clear that video conferences are strictly required or that they would even work for most classrooms. To much hassle to set up and still difficult to extract value from time invested. Maybe best to record a video and follow up with one to one sessions as required?

Photo app: I know, not new item, but please, do yourself a favour and use MS Office Lens or equivalent. Why send 4 separate photos instead of a single pdf? Or spend time cropping and aligning photos?

Sunday 15 March 2020

#BeingPartoftheSolution

This post was first published as LinkedIn article
https://www.linkedin.com/pulse/beingpartofthesolution-juan-carlos-cabrejas/



1-minute summary: if you are a tech savvy parent, reach out to your children´s school and enquire if they need support to work remotely. This is a great opportunity to improve the digital literacy and skills of students, teachers and parents. Things which are obvious to you may not be obvious to everyone. See below some of my ideas, which are easy to implement.

For the longer version, read on.

I am actually not sure how well prepared most schools are for remote learning. I wouldn't be surprised if some of them are lagging on this aspect relative to many companies. While a lot may depend on available infrastructure, typically people skills and attitudes have a much bigger impact. So I was thinking how I can be of help and decided to provide a few basic tips which may help smooth the next few weeks with some specific easily actionable items.

If you share this, depending on your digital skills or those of your network and the teachers in your area, you may find this article plain obvious. If that´s the case, you are a good candidate to offer help to others which need to work remotely and may need IT support.

Communication: a lot of remote communication takes place through email. My experience with schools is that typically someone takes the last message on a recent thread and replies to all with new information. If a mother (or more typically a father) is not included in the initial message, it is always difficult to bring them back into the list. Even if added, they cannot see previous conversations and others may reply to another thread starting the loop again of missed communication.
Recommendation: set up a distribution list for each class, for example with https://groups.google.com

Remote access: many teachers will have to work from home using a variety of personal computers with Windows, macOS and Linux. If something does not work out, it is typically difficult to troubleshoot remotely their issue unless you can see the screen and take control.
Recommendation: Identify a couple of tech savvy parents per class as extra IT support for teachers. Consider discussing with teachers installation of a remote desk solution, such as anydesk.com which offers a free option for private users.

Security: This is a great opportunity to discuss digital literacy with teachers, students and parents, so probably appropriate to raise awareness of some of the items discussed in https://ssd.eff.org/en in the next months.
Recommendation: As a minimum, everyone should install a password manager, such as KeePassXC which is open source, cross platform and actively being developed. Two factor authentication should be enabled in all services which allow it.

Photo app: some teachers may have printed material already available which they now need to distribute to students. Not all teachers will have scanners at home, and things like books require a long time to scan (if at all possible). Manually cropping and warping photos is time consuming. Reworking material into a digital format even more so.
Recommendation: Consider installing Microsoft Office Lens app on mobile phones. It automatically frames pages and warps resulting image to make it easier for distribution.