Giter VIP home page Giter VIP logo

esp32-machine-emulator's Introduction

ESP32 Machine Emulator

The purpose of this package is to enable you to test-drive (TDD) your MicroPython code in an IDE running on your computer. It seems a lot of people are test-driving python, but not many are test-driving MicroPython. That's understandable, since many MicroPython projects are simple, and emulating real hardware in a test environment is difficult.

The typical approach to emulating hardware is to replicate the hardware programming interface (the API). As of this writing, this library emulates a very small slice of the ESP32 API. I don't know if the library will mature. Hopefully I'll either flesh it out, someone else will take over, or a replacement will emerge.

If you are unfamiliar with the benefits of TDD or test-driving python, I encourage you to take some time to Google and learn. I prefer the pytest library over the unittest library that comes with python3, but you are free to test as you choose.

Getting Started

Take a look at the examples folder in the GitHub repository. Like I said, as of this writing, the library emulates a very small slice of the API, so if you don't see an example for something you want to do, the feature is not available. Feel free to contact me or fork the repo and send me a pull request for the feature.

Here is the github repo for this project: https://github.com/tflander/esp32-machine-emulator

Here is the project on PyPi: https://pypi.org/project/esp32-machine-emulator

Note that the examples are only in the GitHub repo, and are not part of the PyPi distribution.

Supported Features

  • Emulating sending a GPIO digital out signal, and verifying the signal value.
  • Extending the time library to support sleep_ns() and sleep_ms()
  • Emulating the read pulse value of an input pin, such as that received by the echo pin of an HCSR04 Ultrasonic Distance Sensor.
  • Full emulation of HCSR04 Ultrasonic Distance Sensor in examples

esp32-machine-emulator's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

esp32-machine-emulator's Issues

Request for Enhanced MicroPython Module Support

Certainly, here's a draft for an issue you can create for the esp32-machine-emulator project:


Title: Request for Enhanced MicroPython Module Support

Description:
I want to express my appreciation for the fantastic work you've done with the esp32-machine-emulator project. It has been incredibly helpful in enabling me to efficiently write MicroPython code within Visual Studio Code. However, while using this tool, I've noticed that some MicroPython modules may not be fully supported or have code completion. I wanted to kindly request your assistance in enhancing the project by adding support for these modules.

Specifically, the following modules seem to be missing or incomplete in terms of code completion:

MicroPython v1.22.0-preview.54.g95d8b5fd5 on 2023-10-25; Generic ESP32S3 module with ESP32S3
Type "help()" for more information.
>>> help('modules')
__main__          bluetooth         heapq             select
_asyncio          btree             inisetup          socket
_boot             builtins          io                ssl
_espnow           cmath             json              struct
_onewire          collections       machine           sys
_thread           cryptolib         math              time
_webrepl          deflate           micropython       uasyncio
aioespnow         dht               mip/__init__      uctypes
apa106            ds18x20           neopixel          umqtt/robust
array             errno             network           umqtt/simple
asyncio/__init__  esp               ntptime           upysh
asyncio/core      esp32             onewire           urequests
asyncio/event     espnow            os                webrepl
asyncio/funcs     flashbdev         platform          webrepl_setup
asyncio/lock      framebuf          random            websocket
asyncio/stream    gc                re
binascii          hashlib           requests/__init__
Plus any modules on the filesystem

These modules are essential for MicroPython development, and having code completion support for them in the esp32-machine-emulator project would greatly enhance the development experience. Your consideration of this request would be highly appreciated.

Thank you for your dedication to this project, and I look forward to the possibility of an even more comprehensive MicroPython development environment.

Getting started and a weird error message in machine.py

Hi!

I was very happy to see the work you've put down here. I've been frustrated with the difficulties of doing TDD with Micropython. I feel like I've been spoiled with pytest.

I'm still a bit new to Micropython but I'm struggling getting your module to work. When I fire up micropython after upip installing your module I try to import 'machine' and it fails.

$ micropython   
MicroPython v1.12 on 2020-01-11; darwin version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import machine
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "machine.py", line 69, in <module>
AttributeError: 'module' object has no attribute 'sleep_us'

This is a weird message as line 69 looks resonable:

time.sleep_us = sleep_us_for_monkey_patching

This leads me thinking that I'm missing something fundamental.

PS: I'll be happy to contribute a users guide if you want to. I just need to get to the place where I can use the module first. :-)

All the best,

Per.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.