Lex Fridman's posting

I wrote a quite long summary/description of what I did with the SmartBoard project, so makes sense to post it here as well! Project SmartBoard I've been longboarding for a while, and I really enjoyed Raspberry Pi (Zero W specifically, what a beauty) so to make my board much cooler I wanted it to have a perimeter of LEDs that would automatically respond to various actions (turning left/right, accelerating, etc.) with awesome light patterns. The following aren't necessarily in order: Part 1: Get an idea of the functionality I would like it to have. This resulted into: - Brain (Raspberry Pi) - Senses (Some sort of sensor to track movement) - Controller (Infrared controller I found in an old Arduino set) - Output (LED Strip) Part 2: Getting LED Strip. Quiet straightforward research, settled on WS2812B model since it was relatively cheap ($20-25), was waterproof, and had some documentation for RaspPi integration. Part 3: IMU sensor. To track movement I wasn't quite sure what I needed/what existed on the market. TLDR: I ended up purchasing 3 different sensors: - MPU6050 - cheap, only had 6 Degrees of Freedom (DOF) which I later found to be insufficient - MPU9250 - mid expensive, had 9 DOF (Gyro, Accelerometer, +Magnetometer) which in theory would have been very useful, as allows to track Earth's magnetic field as well, but turned out to be defective and ran out of stock - MPU9250+Built-In Kaplan filter - quite expensive for me at the time ($45), but it had a built in Kaplan filter, which I knew I needed from my experiments with MPU6050 (essentially data was very noisy - turns out riding a longboard isn't as smooth as it feels). Part 4: IR remote. I eventually realized that sometimes I want to trigger certain patterns manually, so I've added a remote controller I had lying around from some Arduino set (which was much more difficult than it sounds). Part 5: Raspberry Pi Brain + Circuit. As I'm assembling various components, I'm concurrently writing Python code to test circuits / sensors / led strip response. Since there is a lot to cover, I'll list the problems I overcame to make everything work: - Setting up RaspPi headless (establishing SSH and utilized the wifi capability of Zero W) - Integrating a power source as not to burn LED strip / Rasp Pi since both required very different voltages/currents - Attaching all the inputs/outputs to raspberry pi pins (+ software configurations) - Creating a case sturdy enough to not fall apart, hold all the circuit pieces and be developer-friendly (i.e. could assemble/disassemble easily) - Literally reading Chinese forums to figure out how to utilize the infrared controller - Writing code to interpret the movement signal (knowing if the board is turning is harder than it sounds) - Code to produce awesome led patterns (arguably the most important part) I'm sure there is something I'm missing, but since it's getting too long, I'll stop here, and hopefully, if you are interested, we could talk more about my journey. Again, all of it is documented in my github / blog / projects tab / silly youtube video.

Comments (1)

Python bug/feature which costed me an hour of my life

What's wrong with the code below?

>>> def func(n=5, arr=[]):
...     arr.extend(["hi"] * n)
...     return arr
This function :
  1. Takes in integer value, n and an array, arr
  2. Appends n "hi"s to the array
  3. returns the resulted array
If we call this function, then we get the expected output
>>> func(3)
['hi', 'hi', 'hi']
But... what if we call it again?
>>> func(3)
['hi', 'hi', 'hi', 'hi', 'hi', 'hi']
Wait, what? n is 3, so why do we get 6 "hi"-s ?
>>> func(5)
['hi', 'hi', 'hi', 'hi', 'hi', 'hi', 'hi', 'hi', 'hi', 'hi', 'hi']
huh? 13 times? Why does it append to the previous result?? Well, after playing with various iterations, I came to realize that the default value inside the function definition is created only once. I.e. inside the def func(n=5, arr=[]): python remembers to use created empty array as a default value. But actually, it only remembers the reference to the array, not the array itself. So when it's modified, still in the next call it still refers to the same object, it uses the modified array as a default. Anyway, that's kinda insane and cool, but I've read on StackOverflow that it has some good reasons. I'll post a link later, gotta take a shower.

Comments (0)

Negotiating like a boss (or at least like a champ)

Negotiations are tough. Most of the people I know (myself included) find any sort of negotiation uncomfortable/unnecessary/difficult/scary - pick your word. Of course, almost no one is willing to acknowledge it, because acknowledgment itself implies that others likely took/take/will continue to take advantage of you. Negotiations take time, energy, and, by far the most difficult for me - articulation. Before I give my 20 cents of advice, let me preface by saying that I'm a very agreeable person by nature. I don't like to cause any discomfort or get into confrontations with others. It's easier for me to place myself into someone else's shoes, see the world through their perspective, play my own Devil's advocate, etc. Once, this excessive altruism cause me to willingly burn my feet, but that's a different story. All is to say, my agreeable altruistic friends - I get it. What I eventually came to realize, through a series of unpleasant interactions is that I should treat myself at least as good as others - a reverse of a common biblical proverb. If something causes you discomfort, or if you feel like some salesperson is talking over you with a thousand words per second speed - DO get frustrated, angry, tell them firmly to slow the fuck down. Ask for a paper and write things down, take as long as you need to review all the details of the offer. Think of yourself as your own backup buddy ensuring that none of those shenanigans cloud your mind. When they tell you to pay X, demand to pay only X/10. Be firm. Their goal is to fuck you, so realize that and act accordingly.

Comments (1)