Arduino_Notes - RicoJia/notes GitHub Wiki

========================================================================

Basic Setup

========================================================================

  1. CPU, RAM (2k SRAM, DRAM?), IO, ROM

    • DRAM is "dynamic RAM". Reading: when cap is full, it will leak in a few milliseconds.. So set word to on, bit to 1v, if cap is 2v (full), it will flow from cap to bit; else if it's 0v, it will flow the other way. Write: read, empty the cap, then write.

    • SRAM is for static RAM, faster, using flip-flops (CMOS), no need to fresh. So faster. Used as cache, because it's big in size, and can't fit as much in a chip as DRAM.

  2. Bootloader: software to wait for your program and write to arduino. bootloading is to use an In-System-Programmer (ISP), real hardware

    • Arduino may not have a bootloader on it. So replace it with a new chip
    • get 2k more space.
    • But you can't use USB
    • select port
  3. Baudrate: 9600 bits/second in serial. above 76800. then cable needs to be short

  4. software reset arduino:

    void (*reset)(void) = 0;    // set this function at address 0
    reset(); 
    // HOWEVER, if you print right before reset, serial print might be corrupted
  5. Arduino print number: Serial.print(78, DEC) gives "78"

    • Serial.println(String(execution_time)); print byte
    • WARNING: serial.println will send stuff to serial
  6. Problem with delete[]

    • Try not to delete[] arrays, there are certain complications that we don't find answers for yet.

ESP32

  1. Installation in Arduino

    • Choose DOIT DEVKIT v1
  2. Modes

    • 活动模式:在这种模式下,Wi-Fi和蓝牙发射器和接收器的所有部分都是活动的。在这种情况下,电流消耗在80和260mA之间。
    • 调制解调器睡眠模式:处理器仍处于活动状态,但Wi-Fi和蓝牙已禁用。在这种情况下,电流消耗在3到20mA之间。
    • 轻度睡眠模式:主处理器停止工作,但RTC单元和ULP处理器单元仍处于活动状态。电流消耗约为0.8 mA。
    • 深度睡眠模式:只有RTC单元处于活动状态。在这种情况下,Wi-Fi和蓝牙通信的数据存储在RTC的存储器中。在此模式下,电流消耗在10到150μA之间。
    • 休眠模式:除了用于时钟的RTC定时器和连接到RTC的一些I / O引脚外,所有单元均被禁用。 RTC定时器或连接的引脚可以将芯片从此状态唤醒。在这种情况下,电流消耗约为2.5μA。
  3. About ESP32

    • Datasheet pic alt
    • RTC_GPIO is for low-power mode
      • PWM channel generates a PWM.
      • vin is 5v!
    • ~ means PWM.
    • D for dual core. ours is dual core. MIFA antenna, F shaped antenna, high bandwidth per area
    • has internal LED
    • also has IR comm
    • Power: 5-12v external power
    • SPI flash: spi has choose line, but still slow for memory.
  4. Communications

    1. HTTP, run post and get, but HTTP is quite tricky
    2. WebSocket: persistent HTTP calls
    3. MQTT, iot protocals, light weight, industry standard

========================================================================

Sensors

========================================================================

Bluetooth

  1. serial comm (tx->rx). Should use <SoftwareSerial.h> since there's one tx, rx, and they clash with the comm
  2. default pwd: 1234

ESP 8266

  1. Sample Schematic:

  2. Tutorial

========================================================================

ROS

========================================================================

  1. ros serial: getting started

    • Note: as indicated here, for groovy and above, installing ros_lib is a one-time thing:

      cd sketch_book/libraries
      rosrun rosserial_arduino make_libraries.py .
      
    • Note: ros and serial (like uploading) will clash

    • generate msgs see here:

      # in ros package
      rosrun rosserial_client make_libraries ~/sketchbook/libraries
      
      • Note: catkin_make doesn't delete the old srv file (just overwrites it). So need to delete build and devel if old srv file was generated
    • How to write service see here

    • run the node rosrun rosserial_python serial_node.py _port:=/dev/ttyUSB0

    • A logic error in arduino will make the rosserial topic drop msg.

  2. print float:

    char result[32]; // Buffer big enough for 7-character float
    dtostrf(commanded_angles[i], 6,2, result);
    nh.loginfo(result);
  3. Subscribe: array in .msg is tricky. List them out instead

    • when you reach above 90% memory, the arduino will become spooky
  4. publish: array, string needs to have length specified first. Also, you have to use ptr for deserialization. link

    joint_msg.commanded_angles_length = 6; 
    joint_msg.commanded_angles = &current_angles[0];
    
    joint_msg_pub.publish(&joint_msg); 
    nh.loginfo("hehe");
    nh.spinOnce();
⚠️ **GitHub.com Fallback** ⚠️