Software
General pieces of advice for me
- Exercising regularly really does help.
- Use bash for scripts when the script will run less than 10 times in a lifetime.
- Use python for scripts when you want to be able to edit them.
- Use PlatformIO for embedded development, unless there is no mature rust HAL for a MCU.
- Prefer wgpu over platform specific APIs for graphics programming.
- Always benchmark stuff when optimizing, no exception.
- Try to avoid web development if you can, its hell incarnate.
- After some testing, Music actually slows you down, unless you are doing something that requires no thinking.
- For downloading music,
yt-dlp -x --embed-subs --embed-metadata --embed-thumbnail --add-metadata "https://youtube.com/playlist?list=PLNPkZsUXzlEjvQemMGAnBifR4yNFO4dpb" -N 8 -I -1:-10:-1
More detailed info
2D Rendering
- Denote an image with a single array and a pixel's index can be found by
width * y + x
. - The x coordinate is
i % width
, y isi / width
. - To get a point at a distance r and angle t, relative to point (x0, y0)
- For drawing a simple primitive, use its derivative to get the next pixel, usually the derivative is simpler
- Ok, Fk, This stuff is sub optimal, since it kinda encourages drawing vertically, which is not optimal for the cache.
Line
- A line's equation is
or, where
- When drawing line, a simple
for (x in x0..x1)
usually leaves gaps if , andfor (y in y0..y1)
leaves gaps when , use both with if cases. - Use when when drawing lines to avoid division.
Circle
- A circle's equation is
or,
- Its not worth doing the derivative for a circle, just use the equation.
- A circle can be drawn by only finding 1/8th of it, and mirroring it to the other 7 parts.
Ellipse
- An ellipse's equation is
or,
- Its not worth doing the derivative for a circle, just use the equation.
- An ellipse can be drawn by only finding 1/4th of it, and mirroring it to the other 3 parts.
Rotated Rectangle
- Find the points of upper line and the corresponding point at the bottom part at the same x coordinate.
- Draw a vertical line between these two points.
- Bam, you have a rotated rectangle.
Electronics chapter
General words of caution
- Isolate the grounds of power and signal circuitry
- Prototype a PCB before ordering it.
- Make soldered connections before changing anything else.
- Check code before changing circuitry.
Component sellers
PCB Manufacturing
Quirks of devices
Quirks
NodeMCU
- NodeMCU is a development board that uses the ESP8266 chip, packaged as a ESP-12E module.
- The NodeMCU Board maps the ESP 12E's pins to custom pins named as DX pins.
To Program
-
Using the Arduino IDE.
- Install the ESP8266 board package.
- Select the board as NodeMCU 1.0 (ESP-12E Module).
- Code like you would for an Arduino.
NOTE: The pin numbers in the code are the DX pin numbers, not the GPIO numbers. So, D8 GPIO8.
-
Using platformio.
- PlatformIO has native support for it, go look at the website.
Quirks
- Most boards use CP2102 Serial to USB converter, so if on windows, download it's driver, and if on linux, gentoo in particular, compile that in.
- One may think that the NodeMCU shouldn't be powered by more than 3.3V, but it can be powered by 5V.
- However, you can't have the signal be 5V, as the ESP8266 is a 3.3V device. You can fry GPIOs like this.
- It also has an upper current limit of 12mA per GPIO pin, that's not much.
- Don't connect it directly to relays, have an optocoupler.
- Sudden current demand spikes can also crash it.
- Remember to regularly
yield()
when taking up a core for too long, otherwise it will crash. - Default Baud rate for errors is 76800.
- D3 is mapped to GPIO0, D4 is mapped to GPIO2, D8 is mapped to GPIO15
- GPIO0, GPIO2 and GPIO15 determine the boot mode, so if you are unable to upload code to it, check whether the states of these pins is in the correct state at early boot.
- GPIO15 also acts as chip select for SPI.
GPIO0 (D3) | GPIO2 (D4) | GPIO15 (D8) | |
---|---|---|---|
UART (aka. When you can upload code to it) | LOW | HIGH | LOW |
Flash Boot (aka. When code runs) | HIGH | HIGH | LOW |
- You can pull down a pin by attaching a high value resistor to a ground.
- You can pull up a pin by attaching a high value resistor to a VCC.
- If there is literally no response from the nodeMCU, check the EN pin and the RST Pin, both of these should be high and not fluctuating.
- Serial.print sends data to both USB and the RX, TX pins on board, if using them for something, make sure you are printing only relevant stuff.
- The antenna sucks a little, may dire wiring the antenna manually, some people have reported success, haven't verified personally.
- SPI can be finicky, when a connection is broken, it needs to be reset. My current solution is to just reset SPI and begin a new connection everytime data needs to be sent.
- In particular, MFRC522 module fks with it, sending it to a different boot mode if you connect it's pins to the ones specified above without care.
RC522 RFID Reader
I am referring to the complete module, not just the chip.
If you have metal behind the reader OR the tag, it won't be able to read it.
To mitigate, get a piece of dielectric material, like ferrite and put that between the tag and metal, that is actually how the commercial solution is made.
The better solution is to just buy the metal tags, they are more expensive, but they work better with metal.
Just know this before starting your project.
It fking SUCKS, but is the cheapest, you can get it as low as 50 rupees.
Actually, MFRC522 is the name of the chip, but also commonly refers to the cheap board it is commonly found on.
Somehow the IRQ pin is not supported by the most popular library for reading rfid tags using it for arduino, idk how, that is just how it is.
It alternates between having a tag and not having a tag when sending the command to read a tag, Ping multiple times to get the actual result.
If the boot mode of NodeMCU is wrong, this fker is probably the culprit.
Also, buy in bulk, these things are fragile AF, and can randomly stop working if voltage is not to their liking. Could be dirty DC, could be slightly more voltage, could be slightly less voltage.
These don't have any VRMs or filtering caps, so make sure power is good.
Sometimes you may need to do a SPI Reset, in my experience, even when i had soldered the connections, at this point, i can't figure out why, may be the mfrc522 chip crashes for some reason. Just do a SPI reset regularly.