Emulate Arduino On Pc

0 views
Skip to first unread message

Namuncura Mckoy

unread,
Aug 3, 2024, 4:51:22 PM8/3/24
to ritretigo

Hi all, my boss wants me to use an Arduino UNO r3 to emulate an "USB audio device" that has specific vendor id, vendor name, product id, product name, etc.. Is it possible with the Arduino UNO r3? And if so, how can I do that?

Assuming you get the Arduino to pretend to be this unknown "USB audio device", then what? What exactly do you intend to have the Arduino do? Generating audio data is not something that the Arduino is particularly good at. Using audio data is not something that the Arduino is particularly good at.

Well, I've been asked to use the Arduino UNO r3 to test a driver on a Linux machine. This driver is used to interact with an audio device that i don't have at the moment. However, I have the protocol used by this device to communicate with the driver. So, in order to test the driver, I have to emulate this device's vendor id, vendor name, product id, product name, etc. otherwise Linux will not load the driver.

As you may have already figured out, I don't have much experience with Arduino, so if you have any idea/tip/suggestion, please let me know. At the moment, I am going through the USB/Serial converter code looking for vendor id, vendor name, etc., but I am not really sure what to do once I find them.

V-usb creates a device that emulates a usb device of your choice where you can set the ID numbers , power requirements etc. One kind soul has altered this to run on Arduino with examples and it can be had here .

I would like to start the development of some basic Arduino projects but I don't own an Arduino board yet. Is there a way I can write my code and emulate/test it using a desktop computer so after my board arrives I just have to upload and run my project on it?

Be aware that no simulator will reproduce real-life situations. There have been plenty of posts on the Arduino forum about problems with code or electronics, which turn out to be something subtle, such as:

As for getting ready for the board to arrive, download the IDE and start programming. You can get libraries installed, code written and free of syntax errors, organize it neatly, and be generally ready for the big day when the hardware is in your hands.

Bounce is the basic problem in most beginner projects. That can create multiple input triggers, unwanted noise and makes the project to misbehave. Sometimes can be difficult to identify without proper debug or measurement tools. Knowing about the bounce in switches and tips and tricks on how to solve it is an interesting study for every beginner hobbyist.

LCD1602 is one of the best HMI and has been here for a long time. It helps in debugging projects during run time, we can also use it along with a keypad to make a completely practical HMI (human-machine interface). Very easy to use, and easy to learn about programming.

FastLED is a second revolution in the history of LEDs. It was never easier than now to program multiple LEDs with just one Arduino Pin. With the growing FastLED community (reddit, wokwi-Discord, and others) and FastLED examples and libraries, This is one of the most important elements in the wokwi Simulator.

Emulare: is a general purpose hardware emulator. It aims to provide a central interface to build electronic simulations for embedded software development. At present emulare focuses on the ATMega line of microcontrollers (Arduino UNO has the ATMega processor).

SimAVR: is a new AVR simulator for linux, or any platform that uses avr-gcc. The simulator loads ELF files directly, and there is even a way to specify simulation parameters directly in the emulated code using an .elf section. It supports emulation of many ATMega processors and it is mentioned that it's easy to even add new ones.

Amtel Studio: This doesn't seem to mention the term emulation, but it is a sophisticated IDE to debug your code for many platforms specially Arduino. Atmel Studio 7 features seamless one-click import of projects created in the Arduino development environment. Your sketch, including any libraries it references, will be imported into Studio 7 as a C++ project. Once imported, you can leverage the full capabilities of Studio 7 to fine-tune and debug your design. Atmel Studio 7 fully supports the powerful embedded debugger on the Arduino Zero board. For other Arduino boards, shield-adapters that expose debug connectors are available, or switch to one of the many available Xplained-Mini/PRO boards to fully leverage the Atmel HW eco-system.

You can still use simulators such as EasyEDA to test your code and in most cases be able to run it on the device. But note that given the nature of electronic components, you may have to provide external resistors, capacitors etc to get the expected results.

Virtualbreadboard has a new VBB4Arduino 'Two Arduino's' edition which includes BOTH a JVM Arduino emulator AND a AVR Instruction set simulator with examples that cover almost all of the Arduino distribution examples and a bunch of peripheral hardware - LCD's, WS2812 Neo LEDS, Motors, Servo's, Logic Analyser and more.

You could e.g. use my simulator.It is especially suitable for PLC-like applications, where multitasking is achieved by cyclic evaluation of interconnected circuit-like objects: Timers, Markers, Latches, Oneshots and Registers.You can use it to simulate your controlled system as well, as becomes clear from the examples in the download. It has modest visualisation capacities, can draw timing charts, and allows you to access and alter c.q. force all variables in real time during a running simulation. Also you can freeze time. When you're satisfied with the behavior of your control it generates the C code to be uploaded to an actual Arduino.

In practice, you would probably not be calling the digitalWrite functions directly -- you'd call a function in your library, then verify that the "world state" (represented here by the GODMODE construct) matches what you expected your library to do.

Yes you can, and fairly easily. There is a wonderful online simulation (completely free) called TinkerCAD. It has an excellent breadboard simulation, with parts like transistors, LEDs, ICs, and Arduino. You can program the Arduino and run it all in a live simulation that includes interactive inputs (pushbuttons, DIP switches, etc.).

That's not all. It also includes in a separate tab schematics for your circuit, and another tab for PCB design of your breadboard circuit! Or, you can just make your schematics from scratch and make your PCB from there.

You can have your circuit designs made and you can buy them. You can do all of this in circuits.io, and you aren't risking messing up your actual Arduino. It also has warning indicators in the simulation (for example, if you didn't use enough resistance on an LED, or an IC).

An alternative to simulators are services similar to online compilers like coliru, which allow users to build and run their code on a remote system. This approach has the same limitations as online compilers:

Typically, most online compilers provide users with access to command line and process STDOUT. On Arduino, providing remote access to the serial port would provide a similar degree of control: users would be able to observe and control their running sketch through UART, but would not be able to connect/remove wires, push buttons, act on external sensors, etc.

Surprisingly, I couldn't find any such online services, so I ended up writing my own - HW Farm. If you have a web server and Arduinos you can connect to it, you can install HW Farm on it and let people access those Arduinos through a web interface. I also host such a server myself, which has a single Arduino Mega with a bunch of I2C devices connected to it. You can try it out, but don't expect it to be online and available all the time.

With the need to drive some electronics with open collector / open drain outputs from Arduino, I just realized that it may just be possible to emulate open collectors with a bit of smart programming. Maybe I'm not the first to come up with this idead, maybe someone has tried it before and has good or bad experience with this method.

But I was hoping to reduce the number of external components as much as possible because I haven't got a PCB, ... The only thing I'm worried about with my option is if the slopes will stay well defined during the time that the pin is switched from output to input and ........ enabling the pull up. That'd be solved with yours.

Today I pulled out my oscilloscope and checked the slopes with the internal pull-up trick. It is a drama, the waveform doesn't even remotely look like it is digital!
This was easily solved with an external 10k pull-up as suggested!

One of the primary reasons that open collector outputs exist at all is for interfacing with NON-TTL level devices such as driving analog circuits or higher power transistors. Example: An open collector output can be attached to a circuit using 24V or so, you can have ttl chip have a 24v output because the last transistor has its collector connected externally from the rest of chip. The collector is not referencing 5V logic inside the chip. Any kind of internal pullup changes that.

The nice property of open-collector / open-drain outputs is that you can connect several outputs together without risking anything burning out - even if several outputs are active at the same time. A good example is the OneWire bus, which is a very clever design...

I wonder if it's possible to emulate 70's and 80's microcomputers, such as the TI-58/59, or COSMAC ELF with Arduino? I want to learn assembly language! I'm aware of the emulators for PC and mobile but I wonder if there's anything for Arduino.

Well given that they are the same power then no. Also the ATMEGA chip is a micro controller not a micro processor. It has Harvard architecture meaning that the program space and data space are separate. The old computers use Princeton architecture meaning that the program space and data space are the same thing.
Add that to the lack of memory of an arduino compared to an old school computer and the no gets louder.

c80f0f1006
Reply all
Reply to author
Forward
0 new messages