Monday, December 23, 2024

What is an H Bridge?

 An H-bridge is a circuit that lets you control a DC motor to go backward or forward. You normally use it with an integrated circuit and a microcontroller, such as an Raspberry Pi Pico to control dc and step motors. This L298N is a plug and play H Bridge motor driver.

H Bridge Schematic
H Bridge Schematic

A DC motor spins either backward or forward, depending on how you connect the positive and negative to the motor poles. 

If you close switches 1 and 4, you have power spinning the motor in one direction.

Raspberry Pi Pico 2W
Close switches 2 and 3, and you have changed the polarity by changing the positive and negative being received by the poles. The motor will spin in the opposite direction.

Usually, you control the transistors from an Integrated circuit and microcontroller, such as Raspberry Pi Pico.

The transistors you choose must:

  • Handle enough current
  • Use PNP (or pMOS)
  • Have a low voltage drop between collector and emitter
  • The most important thing is that all the transistors can handle enough current for the motor. Otherwise, it will burn out. For example, if the motor draws 1 Ampere of current, you need transistors that can handle a minimum of 1 Ampere.


Buy Now H Bridge Motor Driver L298N For Arduino, Pico, Raspberry Pi
Buy Now H Bridge Motor Driver L298N For Arduino, Pico, Raspberry Pi



Saturday, December 7, 2024

What is the difference between MicroPython's utime library and Pythons time library?

 The utime and time libraries in MicroPython serve similar purposes but have some differences in their implementation and functionality. 

Here's an overview of each:

utime Library:

Purpose: The utime module is specifically designed for MicroPython. It provides functions for working with time-related tasks, such as sleeping, getting the current time, and measuring time intervals.

Functions:

  • utime.sleep(seconds): Suspends execution for the given number of seconds.
  • utime.sleep_ms(milliseconds): Suspends execution for the given number of milliseconds.
  • utime.sleep_us(microseconds): Suspends execution for the given number of microseconds.
  • utime.time(): Returns the current time in seconds since the epoch.
  • utime.ticks_ms(): Returns the number of milliseconds since the board was powered on.
  • utime.ticks_us(): Returns the number of microseconds since the board was powered on.
  • utime.localtime([secs]): Converts a time expressed in seconds since the epoch to a tuple representing local time.


time Library:

Purpose: The time module is a standard Python library for handling time-related tasks. While it is not always fully implemented in MicroPython, some functions may still be available depending on the specific MicroPython port.

Functions (standard Python):

  • time.sleep(seconds): Suspends execution for the given number of seconds.
  • time.time(): Returns the current time in seconds since the epoch.
  • time.localtime([secs]): Converts a time expressed in seconds since the epoch to a struct_time representing local time.
  • time.strftime(format[, t]): Formats a struct_time or tuple representing local time to a string according to the specified format.

Key Differences

MicroPython-Specific: utime is specifically tailored for MicroPython and includes functions that take into account the limited resources of microcontroller environments.

Precision: utime provides more precise time functions (e.g., sleep in milliseconds and microseconds) suitable for microcontroller applications.

Availability: The standard time module may not be fully available in all MicroPython ports, whereas utime is more consistently supported.

How to Figure out needed Voltage, Resistance and Current

This formula will tell you what resistance you must provide to reduce the voltage of the power source to the needed\safe component voltage. ...