Jump to content

Joao Paulo

Members
  • Posts

    20
  • Joined

  • Last visited

Posts posted by Joao Paulo

  1. Hi,

    I was trying to modify the example test_I2C_CLS-TMP2.py( https://github.com/Digilent/WaveForms-SDK-Getting-Started-PY) to read LM75A from NXP, but I could not get rid of this error.

    • I checked i2c address ( 0x48 7bits or 0x90 bits). I also tried with both

    image.thumb.png.9185a3056bf81e5909224dfe335b84dd.png

    here is the code not working:

    from WF_SDK import device, supplies     # import instruments
    from WF_SDK.protocol import i2c         # import protocol instrument
     
    from time import sleep          # needed for delays
     
    device_name = "Analog Discovery 3"
     
    """-----------------------------------------------------------------------"""
     
    # connect to the device
    device_data = device.open()
    device_data.name = device_name
     
    """-----------------------------------"""
     
    # define i2c addresses
    TMP2_address = 0x48
     
    # initialize the i2c interface on DIO0 and DIO1
    i2c.open(device_data, sda=1, scl=0)
     
    try:
        # repeat
        while True:
    
     
            # read the temperature
            message, error = i2c.read(device_data, 2, TMP2_address)   # read 2 bytes
            value = (int(message[0]) << 8) | int(message[1])    # create integer from received bytes
            print(value/256.0) 
     
            # delay 1s
            sleep(1)
     
    except KeyboardInterrupt:
        # exit on Ctrl+C
        pass
     
    # reset the interface
    i2c.close(device_data)
     
    # stop and reset the power supplies
    supplies_data.master_state = False
    supplies.switch(device_data, supplies_data)
    supplies.close(device_data)
     
    """-----------------------------------"""
     
    # close the connection
    device.close(device_data)

    In the Waveforms, it was fine. Also, I tried the test_temperature.py and it runs fine too. Then I modified the Digital_i2c.py and it worked fine. Here is the working code. I know it works but I would prefer to use the nice ready modules already written. Any ideas?

    """
       DWF Python Example
       Author:  Digilent, Inc.
       Revision:  2018-07-23
    
       Requires:                       
           Python 2.7, 3
    """
    
    from ctypes import *
    import math
    import sys
    import time
    import struct
    
    if sys.platform.startswith("win"):
        dwf = cdll.LoadLibrary("dwf.dll")
    elif sys.platform.startswith("darwin"):
        dwf = cdll.LoadLibrary("/Library/Frameworks/dwf.framework/dwf")
    else:
        dwf = cdll.LoadLibrary("libdwf.so")
    
    hdwf = c_int()
    
    print("Opening first device")
    #dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf))
    # device configuration of index 3 (4th) for Analog Discovery has 16kS digital-in/out buffer
    dwf.FDwfDeviceConfigOpen(c_int(-1), c_int(3), byref(hdwf)) 
    
    if hdwf.value == 0:
        print("failed to open device")
        szerr = create_string_buffer(512)
        dwf.FDwfGetLastErrorMsg(szerr)
        print(str(szerr.value))
        quit()
    
    print("Configuring I2C...")
    
    iNak = c_int()
    
    dwf.FDwfDigitalI2cRateSet(hdwf, c_double(1e5)) # 100kHz
    dwf.FDwfDigitalI2cSclSet(hdwf, c_int(0)) # SCL = DIO-0
    dwf.FDwfDigitalI2cSdaSet(hdwf, c_int(1)) # SDA = DIO-1
    dwf.FDwfDigitalI2cClear(hdwf, byref(iNak))
    if iNak.value == 0:
        print("I2C bus error. Check the pull-ups.")
        quit()
    time.sleep(1)
    
    rgTX = (c_ubyte*1)(0)
    rgRX = (c_ubyte*2)()
    while True:
        #print("Write and Read with reStart:")
        dwf.FDwfDigitalI2cWriteRead(hdwf, c_int(0x48<<1), rgTX, c_int(1), rgRX, c_int(2), byref(iNak)) # write 1 byte restart and read 16 bytes
        if iNak.value != 0:
            print("NAK "+str(iNak.value))
    
        print(list(rgRX))
    
        # Convert temperature data to Celsius
        raw_temperature = struct.unpack('>h', bytes(rgRX))[0]
        temperature_celsius = raw_temperature / 256.0
        print(temperature_celsius)
        time.sleep(1)
    
    dwf.FDwfDeviceCloseAll()

     

  2. Hi,

    I have a small problem with I2C master tab.

    I am at waveforms 3.17.1 and I am trying to use the protocol tab with DD device.

    My intent is to read an address on a device, which is 16bits wide address. It happens that I can only read the first address 0000h. Even if I change the SubAddress to 0001h, it will still read 0000h

    I made it work in the custom tab, but not in this. Is it supposed to be this way?

     

    Thanks,  

    image.png.9eb4285c7073e9a7bc3565a0e3ce9178.png

     

  3. Hi @Kristoff

    At the time I abandoned my OpenScope because I could not use it anymore. Then, I found it here again and wanted to try again to bring it to life. I am not sure if the project already ended or so. here is what did, but I do not know if it is important anymore.

    It connects to Wi-Fi and before I programmed the firmware with a PicKit ( the version is in the log ).

    I am able to go on with it now :)

    openscope_wifi.txt

  4. Hi, I had the same problem and can't get past "error connecting / make sure the agent is running" message.

    On 08/12/2017 at 3:50 PM, sudharsan.sukumar said:

    Try going to the settings page and setting the timeout to a higher value. I've attached a picture of the settings menu and you can see the http timeout setting under advanced.

    -Dharsan

    wflhttptimeout.PNG

    That trick I quote worked, but it's strange because I was normally using my OS and then it stopped working and I had to do this workaround. I'm attaching dxdiag report so you have more in hands if you try to figure out what's going on. By the way, my OS does not connect to Wi-Fi anymore, I can select a network, set its password, but no connection is set...

     

    Thanks

     

     

     

    DxDiag.txt

×
×
  • Create New...