發表文章

Programming The Robot Car

圖片
    When connecting the USB2TTL to the control board, NEVER USE THE 5 VOLT LINE . It will burn the microcontroller. You must not power up the control board (inserting USB2TTL to PC will power up the 3.3 volt line) unless all connections are properly established. That is, connect the USB2TTL to the control board first.  Connect the USB2TTL to PC afterward. Blink the LEDs There are three controllable LEDs. A blue LED comes with the MCU module. The control board bears a green LED and a yellow LED. The first program to write is to blink the LEDs in the background and control them in the main() function. /* main.cpp */ oi ai u i e i ; a ou o a e ei e i e ou i u io e u e a e O O O A A O }; e u e o o UE EE E O }; oi e e o o e a e ; i ai oi e UE O ; ai ; ai o 1 e o u i a i e e EE O ; ai ; a o...

PID Speed Control

圖片
    In this post, all codes are NOT tested. the PIDs are not tuned yet. Derived wheel rotation speed from Wheel Count Have you ever calibrated the wheel counter? Let me give you some data. 1. one revolution = 60 counts 2. wheel diameter = 56 mm 3. sampling time = 2.5 ms What do you think about the MAXIMUM change in count per 2.5 ms? Doing a simple arithmetic, you will learn that it is not likely to exceed 15 counts per 2.5 ms. In fact, 1 count per 2.5 ms is equivalent to 1.17 m/s. So 2.5 ms is not suitable for deriving the car speed. 20 ms will give a lowest controllable speed of 15 cm/s. My plan to obtain a speed would be: 1. get the change in count every 2.5 ms and save it for at least 8 cycles. 2. sum up 8 consecutive readings every 2.5 ms to obtain speed as counts per 20 ms. I will use 1 integer to hold 8 samples. Recall that each sample's value would not exceed 15, so 4 bits is enough. Integer is 32 bits long  (stm32f103 is 32-bit MCU), so it can hold 8 samp...

Labelling Your Robot Car

圖片
  Please enter your student ID EIE3105 21234567D EIE3105 EIE3106 Student ID: Print this page and cut out the label. The width of the label is around 5 cm. You may need to scale your printout. Use glue or otherwise, stick it onto the car as shown. Please do not cover the label with transparent tape or any protective coating.

PlatformIO

圖片
   A student wanted to use PlatformIO for coding. I have heard of it for a while and would like to give it a try. It has an advantage of covering many platforms: stm32, avr, pic32. It provides all the tools (compiler and uploader) in a single installation. And it is rich in editing features. It also provides a number of popular frameworks such as arduino (I don't like it but its really good for high school students and hobbyist). I just tested it for our black pill board. It works! There is only one difference. It changes the stm32 header file to stm32f1xx.h. Whereas keil uses stm32f10x.h AVR - non arduino System Clock Setting on STM32F103 Project The default setting in PlatformIO is found to be 8 MHz for APB2. The setting in Keil is 72 MHz for APB2 and 36 MHz for APB1. The following code will boost up the frequencies. RCC->CFGR = RCC_CFGR_PLLMULL9 | RCC_CFGR_PLLSRC | RCC_CFGR_PPRE1_DIV2; RCC->CR |= RCC_CR_HSEON; while (!(RCC->CR & RCC_CR_HSERDY))...

One Liners

  Scale Kicad Footprint awk '{{for(i=1;i<=NF;i++){if($i~/\((start|end|center|at)\>/){$(i+1)=$(i+1)*0.6667;$(i+2)=($(i+2)*0.6667)")"}}};print}'

Programming Joypad with Arduino Uno R3 and HC05 (Old version)

圖片
    It is a wifi remote controller built with arduino uno and HC05 wifi module. It is powered by 2 pieces of lipo batteries. Construction Pin Assignment Pin Function remarks PB0 key drive SW20, SW30 PB1 key drive SW21, SW31 PB2 key drive SW22, SW32 PB3 LED PB5 LED UNO PD0 RX UART PD1 TX UART PD2 key sense SW2, SW20, SW21, SW22 PD3 key sense SW3, SW30, SW31, SW32 AREF ADC battery PB1 ^ PB0 < PD2 > PB2 ...

Control Adaptor Board (Old version 2020)

圖片
  Construction    Pinout   Example Program Please visit The Robot Car for example program. MCU Pin Assignment Pin Function Remark Configuration|Mode A0 GPIO LED 0010=2 (2MHz) A1 TIM2_CH2 counter right 0100=4 (default) A2 TX2 HC06 1010=a (AFPP) A3 RX2 HC06 0100=4 A5 SCK1 path sensor 1010=a A6 MISO1 path sensor 0100=4 A7 MOSI1 path sensor 1010=a A8 TIM1_CH1 motor left 1010=a A9 TIM1_CH2 motor right 1010=a A10 TIM1_CH3 HC-SR04, echo 0100=4 A12 GPIO button 0100=4 B0 ADC12_IN8 battery 0000=0 (analog) B6 GPIO LED 0010=2 B7 TIM4_CH2 counter left 0100=4 ...