Giter Club home page Giter Club logo

rp2daq's Issues

Digital Input

Hi,
I was trying to add a x10 attenuation button to the oscilloscope. using a 2-contact switch which one of those is unused.

image

Screenshot from 2024-04-15 08-25-09

image

switch have two contacts which one of them is free (as image). how is good for me to know that whether this switch is pressed or not (want to detect key press automatically on PC)?

Thanks

Calibrate frequency accurately

It appears that the clock frequency is few % off from nominal 250 MHz. This may be an issue with accurate timing applications! Will have to check this.

STM32

Hello there,
Do you know any firmware that utilities use stm32's ADC for using as sampler for osciloscope?
Not sure but i think stm32f4 can handle 3 channels of ADC, up to 2 Msps for each channel.

page 105 of datasheet
image

Thanks

Rewrite port handler to support software-controlled disconnect & reconnect

Double initialization of one device must be blocked.

The 2nd call somehow manages to connect to already connected device, but the identify callback
gets redirected to the first Rp2daq object:

In [2]: rp2daq.Rp2daq()                                                                                                                                       
2024-04-06 11:54:19,091 (MainThread) connected to rp2daq device with manufacturer ID = E66138935F6F8E28
Out[2]: <rp2daq.Rp2daq at 0x7f8dfee52c70>

In [3]: rp2daq.Rp2daq()                                                                                                                                       
2024-04-06 11:54:23,229 (Thread-273) Warning: Got callback that was not asked for
		Debug info: {'report_code': 0, '_data_count': 30, '_data_bitwidth': 8, 'data': b'rp2daq_231005_E66138935F6F8E28'}
2024-04-06 11:54:23,373 (MainThread)    port open, but device does not identify itself as rp2daq: b''
2024-04-06 11:54:23,374 (MainThread) Error: could not find any matching rp2daq device

So on line "[3]" we should have detected the device was not available, and reported an error instead.

Related to this: the port handler process must stop once we have sw-disconnect, then don't report hw disconnect and allow for clear reconnect.

In [4]: rp.quit()                                                                                                                                             
 In [5]: 2024-04-05 11:16:13,790 (MainThread) Device disconnected, check your cabling or possible short-circuits  

Also related: rp.quit() should release COM port on Win10, so that one can run it again.

And if there is a long command (like synchronous stepper_move) when the device gets physically disconnected, it hangs forever - because it ignores the disconnect event, and waits for the report over USB which never comes.

And when a device is still actively reporting some data (infinite ADC, gpio edge events etc.) and a script is re-started, it randomly won't initialize, because initialize immediately expects a specific short report. Maybe the device should be somehow reserved to stop any other reports (?), then port flushed, then called the init.

RPI Pico Carrier Board

Hi,
Thanks for great project. could you suggest a simple carrier board for RPI pico to turn it into oscilloscope?
A very simple one like THIS (with 2 resistor, 3 diode and 1 capacitor) could work with PICO version?
I am also wrapping up to make next version of C# oscilloscope.

Multiprocessing error on Windows 11: ctypes objects containing pointers cannot be pickled

The commit 4ee6530 (from Jun 9 2023) introduced multiprocessing; it works flawlessly on Linux, but on Windows 11 this throwed

C:\Users\ts\rp2daq-main> python .\hello_world.py
2023-08-29 13:48:14,459 (MainThread) connected to rp2daq device with manufacturer ID = E66118604B826B2A
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1520.0_x64__qbz5n2kfra8p0\Lib\multiprocessing\spawn.py", line 113, in spawn_main
	new_handle = reduction.duplicate(pipe_handle,
				 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1520.0_x64__qbz5n2kfra8p0\Lib\multiprocessing\reduction.py", line 79, in duplicate
	return _winapi.DuplicateHandle(
		   ^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [WinError 50] The request is not supported

This is critical, as it disables rp2daq use from Windows.

Interfacing With C#.NET code

Hello there...
Thanks for the great library.
I am trying to interface your firmware with my C# code. In C# I need to read the ADC values of RPI pico.
I was wondering if you please can give me some direction on:

  • How to find the device
  • How to start ADC reader on device
  • How to Read and interpret data

It is more about the communication protocol.
I'm trying to make a super simple oscilloscope with WPF and C#.

Thanks again.

Different response from PICO in windows and ubuntu

Hi,
I was trying to diagnose the data problem i've got in the windows. so did try to get infinite blocks by ADC.
I simply send a command to PICO, which is :

0x0A,0x04,0x10,0xe8,0x03,0x01,0x01,0x00,0x60,0x00

equivalent to this I think

command

I assume after sending this code to PICO, i'll get a 24 byte of block info. The bitwidth is [3]th byte of header followed by 1500 bytes of sample data. i constantly read 24 byte then 1500 byte over and over. on ubuntu my bitwidth is always 12 but in windows, after block 10 or 11 it will start do get different bitwidth for each block. Note that i execute same code on windows and ubuntu, only need to comment out portname line.
I think is because of some transfer problem maybe.
do you have any idea what is the problem?

here is the code:

import time
import serial
import struct

## User options
#width, height = 1000, 1000
#channels = [0, 1, 2,] #,  3, 4]     # 0,1,2 are GPIO 26-28;  3 is V_ref and 4 is internal thermometer
#kSPS_per_ch = 100 * len(channels)  # one-second run

import rp2daq
import sys
import tkinter

#rp = rp2daq.Rp2daq()


#port = "/dev/ttyACM0"
port = "COM6"
ser = serial.Serial(port=port, timeout=1)

ser.write(struct.pack(r'<BBB', 1, 0, 1)) 
time.sleep(.15) # 50ms round-trip time is enough

try_port = ser
   
id_data = ser.read(try_port.in_waiting)[4:] 

print ("connected to " + str(id_data))

dt = bytes([0x0A,0x04,0x10,0xe8,0x03,0x01,0x01,0x00,0x60,0x00])

print(dt)

ser.write(dt) 

time.sleep(.15) 

sizeToRead = 1500

cnt =0;

while True:
    header = ser.read(24)
    
    print(str(cnt)+ " th block, bitwidth: " + str(header[3]))
    ser.read(sizeToRead)
    cnt = cnt+1

2023-09-01 05_55_40-Windows PowerShell
Screenshot from 2023-09-01 09-22-29

Edge Detection

Hi,
How does the Edge Detection works? is it a trigger which tells the ADC to when take samples?
I would be thankful if you give me some info about it's logic.
Thank you

Suggestion

First of all thanks and congrats for the innovative project.
Currently the compiled firmware (I mean /build/rp2daq.uf2 file) is placed inside the project files. I would like to suggest you to publish the compiled binary file as a release file. I think this is how usually the binary files are published in github.
also the version control would be easier and files can be visible from release section:
https://github.com/FilipDominec/rp2daq/releases

Most examples currently don't work, due to multiprocessing

TR;DR When performance optimisation made me to introduce multiprocessing in the rp2daq module, it has broken all example scripts here. Instead of expanding the code of the examples, I demonstrate how to patch the multiprocessing.Process class so that no changes in user code is required.

Rationale The multiprocessing module turns out necessary for fast & reliable USB communication, and its compatibility with both Windows & Linux stipulates the use of the "spawn" approach instead of "fork". This in turn allegedly requires that a part of the executed script code, excepting imports and some trivial definitions, is fully enclosed in a "guard":

if __name__ == "__main__": ...

.... clause, as discussed in multiprocessing module's Programming Guidelines. Otherwise spawning the secondary process would result in an infinite chain of further processes - a fork bomb, or rather a spawn bomb here.

This has been puzzling people for over 10 years without anybody actually bringing another solution: https://stackoverflow.com/questions/22595639/best-practices-for-using-multiprocessing-package-in-python?rq=4
https://stackoverflow.com/questions/48306228/how-to-stop-multiprocessing-in-python-running-for-the-full-script
https://stackoverflow.com/questions/48680134/how-to-avoid-double-imports-with-the-python-multiprocessing-module
https://stackoverflow.com/questions/50781216/in-python-multiprocessing-process-do-we-have-to-use-name-main
https://stackoverflow.com/questions/55057957/an-attempt-has-been-made-to-start-a-new-process-before-the-current-process-has-f
https://stackoverflow.com/questions/57191393/python-multiprocessing-with-start-method-spawn-doesnt-work
https://stackoverflow.com/questions/70263918/how-to-prevent-multiprocessing-from-inheriting-imports-and-globals
https://stackoverflow.com/questions/77220442/multiprocessing-pool-in-a-python-class-without-name-main-guard

With all due respect to the python's core module developers, I consider this necessity for the "guard" a very bad UX design decision, because it cannot be hidden in the module - instead it is propagated to all scripts that import it. It apparently breaks the principle of least astonishment, leads to repeating code, also it is ugly, complicated, and fairly hard to explain.

One of core principles of rp2daq is to resolve all necessary complexity inside its code, thus enabling the user to write very short, easy-to-read scripts as means for routine instrumentation control. Therefore, the "guard" clause is utterly unacceptable for this project.

Fortunately, a multiplatform, and arguably quite elegant solution exists.

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.