Skip to content

Instantly share code, notes, and snippets.

@futureshocked
Created April 26, 2021 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save futureshocked/fde8f0f993a0e30725d3e12e65702aea to your computer and use it in GitHub Desktop.
Save futureshocked/fde8f0f993a0e30725d3e12e65702aea to your computer and use it in GitHub Desktop.
This script shows how to read voltage from AIN0.
'''
LJ - 10.30 - AIN0_read.py
This script shows how to read voltage from AIN0.
Components
----------
- LabJack T4
- Potentiometer
- Midlle pin to AIN0
- Left pin to VS
- Right pin to GND
- Wires
- Breadboard
Course
------
Data acquisition and automation with LabJack
https://app.techexplorations.com/courses/labjack/
'''
from labjack import ljm
import time
# Get handle to LabJack device
handle = ljm.openS("ANY", "ANY", "Peter_T4")
#handle = ljm.openS("ANY", "ANY", "ANY") # Any device, Any connection, Any identifier
#handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier
#handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier
#handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier
info = ljm.getHandleInfo(handle)
print("Opened a LabJack with Device type: %i, Connection type: %i,\n"
"Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" %
(info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5]))
# Setup and call eReadAddress to read a value from the LabJack.
address = 0 #Address for AIN0
name = "AIN0"
dataType = ljm.constants.FLOAT32 #UINT32
while True:
result_address = ljm.eReadAddress(handle, address, dataType)
result_name = ljm.eReadName(handle, name)
print("\neReadAddress result: ")
print(" Address - %i, data type - %i, value : %f" % (address, dataType, result_address))
print("\neReadName result: ")
print(" Name - %s, value : %f" % (name, result_name))
time.sleep(1) # Sleep for 1 second
# Close handle
ljm.close(handle)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment