Post 6, week something

First of all, for my update on learning, check out my personal blogging site that has just been completely rebuilt (it may look empty).

Update: no need to check there anymore, I copied and pasted the content below.

Over the past few weeks, I have been working to figure out the logic and structure of my car’s code. After all, I have to do some planning. This involves a lot of counting and it is like probability, where you have to consider every possibility. I have 4 sensors that I am working with, and I have to figure out how their input will effect my motors in different situations, like when the car is just put on the track. Now, I have basically finished all the logic, but have yet to actually write the code.

These are some of my logic diagrams. I tried doing a mind map, but I think it is better if I do this first and then maybe see if I need a mind map

Another thing that I have to figure out is how I can write my code. Obviously, I can do like fifty “if…” statements for every possible input, but that is very tiresome, and it does not look professional. My dad suggested a statement, but he doesn’t know python, and that statement is only for C. Other statements that people suggested to me, I don’t understand at all, so right now I am reading several books on python and doing an online course hosted by U of Waterloo.

It’s called Python from Scratch

I haven’t started writing the code yet, but I know I should really hurry up, because if my code don’t work, oh well, I won’t have anything to present on in-depth night! So I should probably allow some time for me to debug and add for functions that I would love to have, if I have time. These are things like a new mode that uses 3 ultrasonic sensors, online viewing and control from the car’s Raspi camera, etc.

image3 image1 image4


Below is some example code I have:

# -*- coding: utf-8 -*-
import time 
import RPi.GPIO as GPIO
import datetime as dt

GPIO.setwarnings(False) #so no error messeges

GPIO.setmode(GPIO.BCM)#setting the mode for the GPIO pin numberings so the computer grabs the right pin!
GPIO.setup(24, GPIO.OUT)#Lmotor main 
GPIO.setup(25, GPIO.OUT)#Lmotor
GPIO.setup(26, GPIO.OUT)#Rmotor main
GPIO.setup(27, GPIO.OUT)#Rmotor
UsonicCenterTRIGR = 22#ultrasonic
UsonicCenterECHO = 23#ultrasonic
UsonicLeftTRIGR = 12#ultrasonic
UsonicLeftECHO = 13#ultrasonic
UsonicRightTRIGR = 16#ultrasonic
UsonicRightECHO = 17#ultrasonic
linesensorCenter=5#line sensor C
GPIO.setup(linesensorCenter,GPIO.IN)#line sensor C
linesensorLeft=4#line sensor L
GPIO.setup(linesensorLeft,GPIO.IN)#line sensor L
linesensorRight=6#line sensor R
GPIO.setup(linesensorRight,GPIO.IN)#line sensor R

pwm = GPIO.PWM(24, 50) #50hz
pwm1 = GPIO.PWM(25, 50)
pwm2 = GPIO.PWM(26, 50) #50hz
pwm3 = GPIO.PWM(27, 50)
pwm.start(0) #Load:100-full right now we have no pwm
pwm1.start(0) #Load:100-full right now we have no pwm
pwm2.start(0) #Load:100-full right now we have no pwm
pwm3.start(0) #Load:100-full right now we have no pwm

 #defining the duty cycle, which is the % the motor is working, controls speed

print ("initialized")

#functions help make code neater and organized, and i can just call on these functions later to summon them
def ending(): #the stopping sequence
 print "ending"

 GPIO.output(24, False) #if both motor on same side have 1 or 0 then stop
 GPIO.output(25, False)
 GPIO.output(26, False)
 GPIO.output(27, False)

def stop(): #the stopping sequence
 print "stopping"

 GPIO.output(24, False) #if both motor on same side have 1 or 0 then stop
 GPIO.output(25, False)
 GPIO.output(26, False)
 GPIO.output(27, False)

def goforward(dc,t): 
 GPIO.output(24, True) #if the main is 1, then forward, if the other one is 1, then backward
 GPIO.output(25, False)
 GPIO.output(26, True)
 GPIO.output(27, False)

def gobackward(dc,t):
 GPIO.output(24, False)
 GPIO.output(25, True)
 GPIO.output(26, False)
 GPIO.output(27, True)


def gofwdleft(dc,t):
 GPIO.output(24, False)
 GPIO.output(25, False)
 GPIO.output(26, True)
 GPIO.output(27, False)


def gofwdright(dc,t):
 GPIO.output(24, True)
 GPIO.output(25, False)
 GPIO.output(26, False)
 GPIO.output(27, False)


def gobwdleft(dc,t):
 GPIO.output(24, False)
 GPIO.output(25, False)
 GPIO.output(26, False)
 GPIO.output(27, True)


def gobwdright(dc,t):
 GPIO.output(24, False)
 GPIO.output(25, True)
 GPIO.output(26, False)
 GPIO.output(27, False)


def gohardright(dc,t):
 GPIO.output(24, False)
 GPIO.output(25, True)
 GPIO.output(26, True)
 GPIO.output(27, False)

def gohardleft(dc,t):
 GPIO.output(24, True)
 GPIO.output(25, False)
 GPIO.output(26, False)
 GPIO.output(27, True)


##def testingmode():
## print ("going forwards")
## goforward(90,1)
## goforward(75,1)
## stop()
## time.sleep(1)
## print ("going backwards")
## gobackward(90,1)
## gobackward(75,1)
## stop()
## time.sleep(1)
## print ("fwd right and left")
## gofwdright(90,1)
## gofwdleft(90,1)
## stop()
## time.sleep(1)
## print ("backward right and left")
## gobwdright(90,1)
## gobwdleft(90,1)
## stop()
## time.sleep(1)
## print ("hard right and left")
## gohardright(90,1)
## gohardleft(90,1)
## ending()
def start():
 print ("starting")
 while linesensorCenter == 0 and linesensorLeft == 0 and linesensorRight == 0:
 if linesensorCenter and linesensorLeft and linesensorRight == 0:
 goforward (90)
 elif linesensorCenter == 1:
 goforward (90)
 elif linesensorRight == 1:


##while speedchange:
## for dc in range(50,100, 5):
## pwm.ChangeDutyCycle(dc)
## pwm1.ChangeDutyCycle(dc)
## time.sleep(2)
## print dc,"duty cycle"
## for dc in range(100,50, -5):
## pwm.ChangeDutyCycle(dc)
## pwm1.ChangeDutyCycle(dc)
## time.sleep(2)
## print dc, "duty cycle"
## #minimum 50, 70 to run
##if KeyboardInterrupt:
## speedchange=0
## ending() 

De Bono time:

Here is a list of concepts that my mentor and I talked about last meeting:

  • digitalized learning
  • machine learning
  • logic of a computer
  • human errors
  • debug
  • education
  • alternatives
  • humanity
  • profit vs. everything else
  • etc.

Coincidently enough, during our conversation, which went really off-topic (shhh), we talked and discussed a lot

Courtesy of

about the United Airline incident that happened recently. When I went back to listen to our conversation, I realized that it was the part during our talk in which we brought up the most alternatives! To start, my mentor suggested for us to look at this incident from another perspective.

The passenger that was violently dragged off was actually a terrorist under disguise. The FBI have been tracking him for days, but never found an opportunity to take him down without alerting the media or the public. So they told the flight attendant to basically pick this passenger when they are doing the draw. This way, they can get the job done, and the public or foreign agencies will never know of the secrets they can extract.

Another explanation for the event doesn’t necessarily praise United, but it claims its innocence:


These explanations for the event look at it from another perspective, and offer an alternative way of thinking about the event.

Anyways, back to my actual topic of alternatives, I had a lot of alternatives when considering my car design:

  • how will it work? (line following? obstacle avoiding? real time control? )
  • how should I write and organize the code?
    • using a lot of if statements?
    • finding a way of listing input that will direct me to a certain output?
    • use “def” makes the code more readable than not using it, but it is more work
    • comment makes the code more readable by humans and make me remember what everything does, but is a lot of work as well
  • if I don’t have time, I could just do one mode (line following + one ultrasonic)
  • if the motors don’t work well going at 70% power, I can just not do slower speeds
  • maybe create two different tracks for two different modes, if I am going to have that

Week something, Post 5

Huff, spring break just passed and I haven’t even written this in advance… I need to stop procrastinating…

But anyways, I think it is week 11, but not too positive, and spring break sure is a time to do stuff. I posted two posts on my “diary” website, but yet again, my crappy server broke down and the website is not accessible. So I will just post some of the pictures I posted there here. These are for V1 of my car, built on Mar. 15, 17. If you are on a mobile device like the iPad, click on the images to view the caption (they’re pretty important). If you’re on PC, I don’t know if captions show, but there are captions on most of the photos.

So, after that, I did a few upgrades, fixed the motor that didn’t really work, and plugged all the Input Outputs! I realized that the Pi can never power the motor, on its own, to make it work as normal. So I basically added another power supply to the motors. This means I will have two battery packs on my car, one for Pi, one for the motors. This is V2.0.

In my meeting with my mentor, I started writing code the car. The first step is to set up the initial initialization, like assigning output to the motor’s pins (24-27). Then, I have to figure out a logic for the car. This includes a exclusive list of the things it will perform under one of the many conditions. So much work for me in the coming weeks…


De Bono Time:

The six hat conversation:

First, I would like to say that most of the time we are talking, we are just confirming our thoughts or proposing a solution that may well be the only one suitable, and we are only talking like 30% of the time in the 2 hours, so I will try to skip over some mumble jumble. OH, and also our conversation is in Chinese, so it is hard for me to translate it into English word for word. I will just say the overall message. Legend on bottom.

Me: Telling my mentor the different things I’ve added since he last saw photos of it. (1.0 to 2.0).

my proposed diagram
my proposed diagram

Also tell him of my logic diagram I am working on. Also tell him of my goal for the night, which is to find out if my diagram works, my car’s design works, my motors function, and some python coding if we have time.


Mentor (and me, but mostly him): Confirm what I said, suggest a new method of figuring out what the logic of the car is. Demonstrates the method and work out the car’s reactions to different input values when it is first starting. (put down on the ground and motors are 0) Everyone agrees that this method is a lot better to follow when writing a code. Ask me to list what the car should do in each situation (ex. right IR sensor detects black, nothing else). Discuss about the type of line & and thickness for IR sensor.

20 min. later.

Me: Discuss how to control the motors, and testing a test code to see if motors function.

test code didn’t work,

Mentor: tells me why code won’t work. Deletes, or comments out most of code that didn’t work.

looking up pwm (pulse width modulation or something, it makes the motors spin slower)

Mentor: (don’t know python, but know the usual syntax and logic of the language) Copies a LED code over to the motor, changing some values. It is meant to fade an LED back and forth. He thinks that it should work, because they are both outputs, and there really isn’t much difference between them.

didn’t work at first, but when the work percentage/duty cycle  is higher (spin faster) it works. We tested that it can start moving at around 65% when it was stationary through a lot of trials.

50 min. later.

Mentor: Suggest a new code that don’t fade out, and allow us to call it up pretty quickly using the “def” function. We also discovered that it allows us to change the variables pretty quickly (time and duty cycle). Also suggests that I put comments on my code so I can remember what they do later.

Me: It also makes your code easier to read to other people so they can know what you are doing.

Me: commenting code is boring, basically you just label the code, but I feel like I will probably forget what this line means in like two days, so I should probably still label it.

me labeling code for 20 min.

Some other little things we discussed that I won’t document here, and our meeting is finished.


White Hat – info

Red Hat – feelings, instinct

Black Hat – criticism

Yellow Hat – the good stuff about something

Green Hat – brainstorming/creativity

Blue Hat – the agenda



The End




The 8th week…. (My 4th post)

First of all, here are some updates on the overall progress of my project. I have basically finished all the learning portions of in-depth, and I will move on to constructing my final project. This doesn’t mean that I’m done learning, it means that I will progress from reading 80% of the time to reading 20% of the time. My final project has a lot of things where it could go wrong, and there are a lot of room for improvements and upgrades. So, I think from now on I will learn through doing.
My progress report is, or was, on my personal blog, but the server crashed while I was writing the report and my site, along with several of my dad’s sites went down. (I must have done something wrong, the WordPress sites could no longer be accessed) I have a copied-and-pasted version here, but all the images are gone. Sorry…
Edit: its now back on, go to this address:

Edward de Bono time:

How to listen:

First of all, my mentor had a different idea about the state of the connection when a capacitor is charging and when it is fully charged. From my readings, I thought that while charging, a capacitor allow the flow of current, and when it is done charging, it will block all current, and it will “open” the circuit. (no current could pass through) Through listening, I saw a different perspective and saw that his reasoning are valid, while my perception of what happened could explain the results of an example circuit, his way of seeing things is more valid. In the end, we are both wrong, and we had a laugh about it. It was after my mentor tried to explain to me his views for 20 minutes, using diagrams and everything. He kept using words that I haven’t read about before, and he is sometimes saying things based on the assumption that I know some things, which I may or may not know. For example, the term “short-circuit” appeared in my readings once (I can’t memorize things that well, and it didn’t come to me), and he kept saying that, resulting in me not understanding the whole phrase he is saying. I tried to wait patiently, because I know everything will be written on my face, and asked a ton of clarifying questions. Finally, I got what he was saying, but we decided to search it up anyways. Turns out we’re both wrong! I also got some interesting facts by paying attention to the matters of interest that arose. For example, since some light bulbs use AC, which has voltage that goes up and down, like a wave, those light bulbs are actually flashing. We can’t see they are flashing because the AC frequency is very short. In the US I think it is 60 times per second. Finally, by paying attention to his use of words, like open circuits or using t0 to t1 to describe an event, I can communicate more professionally with others, and also make my words easier to understand for an experienced person.

How to ask questions:

Fishing questions and shooting questions, they are kind of like the surface/shallow and deep questions we learn in middle school. A shooting question has two results, you miss, or you hit the shot. It is very straight forward. A fishing question is like fishing, you throw in a bait, knowing that it will attract a range of fish (or questions), but you won’t know which fish you will catch, or whether you will even catch one. We ask these questions and differentiate between which question to ask all the time. As de Bono observed, we ask shooting questions when we suspect the answer is no, and when we have an idea what we are asking. If we have no clue of the answer, we ask a fishing question.

Just like de Bono observed, we ask for clarification and explanation more than anything else in our conversations. This is very true for my mentor and me, as I often need him to explain something in plainer English. I also asked a lot of questions when the ultrasonic sensor that we finished last time didn’t work this time, after being transported to a different place. I asked for the possibility of some things going wrong to try to cover all the possibilities (shooting questions), like the connection of resistors, the order of the resistors in the voltage divider, whether the GPIO pins we are connecting to are malfunctioning, etc. We changed the GPIO, the variable names in the code, downloaded a version of the code online that people made, and non of that worked. Finally, we realized that it was supposed to be connected to 5v, instead of 3.3v. This part is when I asked a multiple choices question, of which scenario have the greatest possibility of happening, and therefore which one we should check first. I think using the multiple choice question is great because it lets us examine all the options before making a decision.

I asked for an explanation of the meaning of “short circuit”, which I believed to be a circuit without resistors. But that

description didn’t fit in with the context that my mentor was talking about. He explained, using a diagram, that it means, basically, that there is little to no resistance between the two poles. It also means that, like in the diagram below, all points in the red line have a V of 0. That is because they are all connected to ground, and they cannot have a voltage, but suddenly drop to a 0 when it reaches ground, for no reason. Sorry if that makes no sense.

courtesy of

I hope you are still staying with me after 1000 words, but luckily, or not, this is the end.

Courtesy of

Week 6, Post 3

Believe it or not, three weeks have passed since we did our last blog post! During these three weeks, what I found is that schedules are hard to follow. Everything going on, like homework and events that just pops up, seem to make me completely forget about my schedule. I had a meeting with my mentor last week, and it is when he asked me about what I did in the period between our meetings that I realized: I haven’t done a lot. Because of a miscommunication between my dad and I (I thought he said to keep a log), I started to record all my significant progress on a random website that I made with WordPress in the summer, so now you can go on there to see some of my progress, and I won’t document my progress in these posts anymore. (If that’s inconvenient Ms.Mulder just comment on it) The exact link is here, to my posts, but you can also type in or to go to the home page. (the .win one has some weird bugs)

For our journey to a beautiful mind, which we are currently trying to be interesting and know how to respond, here are my reports:

  1. How to be interesting

    • Image courtesy of Just on/off (digital) VS. 0 to 100% dimmer light switch (analog)

      Using the phrase “Now that’s interesting” is like the easiest thing to do so far. My mentor would often bring up points that I have never heard or thought of before. Like when we were talking about analog (-∞-∞) and digital (1 or 0) and resisters in circuits, my mentor pointed out (literally pointed) that those dimming light switches on my wall have a resister that can change in their resistance. So when I turn the light brighter, the dial makes the resistance smaller and when I turn the light dimmer, the dial will make the resistance bigger so there will be less voltage, etc. and there will be less light. I never thought of that before, so I said “The Phrase” and was then able to make other connections in using the resistor. I also tried to find interesting points in a lot of things, so basically everything that he said which I did not know, I commented and made connections to other things.  Because I didn’t record my conversation, I can’t exactly tell you what I used “what ifs” for, but I remember that once when I asked about what would happen if a LED has received too high a voltage and whether stuff will catch on fire if there is more electricity than it is designed for.

  2. How to respond:

    • Ah, asking for clarification is me every minute. For my conversation with my mentor, basically when I ask a question, my mentor would respond, and before he finishes, I would be bursting with another question. He would answer me again, but I would have another question by the time he finishes. This is also something I need to improve on, since I will have a question while my mentor is speaking, and as a result, I usually lose track of what he has to say, and sometimes I would even interrupt. I did supported some of the points that my mentor made and improved some of his points, but that is because I was searching on the internet the same time he is and I found a better way to assemble the ultrasonic sensor than the method he found. I guess that still counts as responding.

Anyways, that is all I have to say for now, it is getting late and I am really tired, probably because I got my shots today. So this is it for now…

PS: don’t forget to check my progress on

Week 3, Post 2…

Two weeks have gone by since my first post, and it was just a blur. For the first two weeks, I was just planning to learn about the Raspberry Pi in general, like its hardware specifications, Linux (Raspbian on the Pi) and a bit of Linux command prompt. My main source of information was two books published by the Makezine, and I find them to be very insightful, current and accurate. The only bad thing is that it is going very fast and lacks explanation in some parts, and I have to read more than twice to understand a shell command in Linux, for example. I did encounter some obstacles, like finals that delayed my process. To admit it, I didn’t do as much as I planned to do, and I think it teaches me to consider in external factors when planning a schedule. Below is a visual I made that contains the basic facts I now know about the Raspberry Pi. Linux commands that I learned are not shown because I couldn’t find a way to display them.
My mentor (I only know his Chinese name, I forgot to ask for English name) and I have set a schedule to meet after church hours, as he goes to the same church as I am. He has given me his CRC last Sunday, but I had forgotten to hand it in. Our last formal discussion was the Sunday after my first in-depth post, so two weeks ago. It was focused on the outlook of my final project, and some difficulties that I might have achieving them. It was more of a fact based talk, rather than opinion based, so there wasn’t a lot of point we could agree, or disagree on. I had just read to chapter 2 in the book then, but I did read Ms. Mulder’s summery on her blog post.

Image courtesy of – Edward de Bono
  • How to Agree: Most of our discussion was in unison, like how we discussed the number of time I should spend on this topic, the ideas that he proposed to make my project work. There was one time when he mentioned a new point about how a car could sense and avoid incoming obstacles that really appealed to me, and its logic was better than my old algorithm. Something that I didn’t agree with entirely at first was that my mentor mentioned that the Python language is easy. The same thing was said by my dad after. But to a newbie like me, it was hard. It was like learning French from English is easier than knowing no language and starting to learn a new one, word by word. I recognized that when my mentor said that because he knows multiple languages and knowing the structure of languages, Python is easy to him. Another influencing factor is that it could be my own conception that is wrong. Everything is hard before you learn it. I appeared to me to be a sweeping generalization. So I agreed that Python is a relatively easy language compared to others (agree with part of statement), in the end, even though it still seemed hard for me.
  • How to Disagree: So for the example of Python is easy mentioned above, I disagreed with part of the statement and politely brought it up because of the experience different between my mentor and me, so I could only say, Python is a comparatively easy language to people who knows other languages. Besides that, I don’t think there was any other disagreements.
  • Image coursey of My intended algorithm

    How to Differ: Now that I remember, one difference that we encountered was how the car should react when it senses an obstacle. I thought it should turn right, turn left, turn left and turn right again, so it would go back on track. But my mentor thought that it would be better for the car to stop and turn around to go back the way it came from. In the end, we reached an agreement that this is based on the road and the obstacles, and that it all depends on the outcomes and functions that we want the car to reach.

I will keep you all “posted”, bye for now…

Why Pi? In-depth 2017 Intro

We’ve arranged a civilization in which most crucial elements profoundly depend on science and technology. – Carl Sagan

Photo a Raspi took –

In today’s world, technology has become an indispensable part of our lives, and for all the reasons, it improves our lives beyond what is previously imaginable. Our tech keeps evolving, and it is to the point now that we don’t need to

Pies –

think about “how to use it” when we have an IPhone in our hands. The creator of Raspberry Pi, a mini single board computer and also the object of my studies, noticed how people

Raspberry Pi model 3 – Raspberry Pi Foundation

started to have less knowledge of programming languages. As a result, he made the Raspi, aimed towards teaching and inspiring an interest of computing in children, but is also commonly used by D-I-Yers because of its low cost and ease of access. As someone who has always loved the idea of learning a programming language, plus making stuff that improves my life, I think there couldn’t have been a better project to do than learning the dynamics of the Raspberry Pi and to make a cool “smart” project with it.

We live in a society exquisitely dependent on science and technology, in which hardly anyone knows anything about science and technology. – Carl Sagan

When I say will learn about the Raspi, specifically, I mean I will learn about Python programming and electronics, which are the basis of creating anything spectacular with the Raspi. It is like how learning computer usually means learning to use Word and send emails. Computers are used for these things, and while the Raspi can do word processing and send emails, it is only in its best in a project, programmed to your will.

How the car may look like –

My project will focus on getting the technical knowledge down, like learning electronics, and then I will start to build my final project, a car that follows lines and knows to avoid obstacles in its path.

The final project, a self-driving car, is going to take some form of artificial intelligence. In computer science, a perfect “intelligent” machine is a flexible agent that perceives the environment and takes actions to maximize its chance of success at a goal. I plan for the car to be able to sense obstacles in its way, and thorough its “intelligence”, it will do some action to avoid it and keep going down the track it is given.

Let’s get Physical!

Learn about what the Raspberry Pi can do, helping children learn physical computing. (click on link above if video doesn’t appear)

I chose this topic because my dad is a computer engineer, and he had just recently discovered the Raspi. He bought one to serve as a smart TV box that can watch YouTube or browse the web. I had also read about a major advancement in one of the companies experimenting with the concept of self-driving cars. I thought then, to combine them together to make one of those cars you see in science fairs. View my schedule of next two months. I have changed my schedule in the contract due to incorrect calculations of how long the project is going to last.

My mentor is someone in my church whom I just discovered to have studied computers. He even knows about the Raspberry Pi, and that would be really, really helpful. Before, I was going to settle for someone who know Python, and there should be many of them, but now I can get help on the electronics sections as well. I had asked him to maybe give me some information about his schooling or experience, but he hasn’t replied me yet, so I could probably bring this up next post.

I hope to be able to put together more and more advanced projects using the Pi after In-depth project, in the fields of home automation and simple artificial intelligence, because my proposed final project is not a very “useful” thing considering that it is a toy. So I will still have a long way to go after the project is finished.