I'm wondering if there is a simple (or at least best practice) way to pass values to (and/or from) an Arduino from a lua script running on a T7. Essentially I want to utilize a T7-pro for a standalone application which has a LCD user interface. Using LCDs on an Arduino is easy because they have extensive libraries for such things, but the analog resolution is insufficient. On the other hand the T7 has plenty of resolution but I don't know an easy way to use it to interface with a display.
Arduino supports both I2C and SPI so I'm assuming that one of those is the way to go. However I don't personally have enough experience with either to know how to deal with them from first principles. If there isn't any significant insight I guess I will just start modifying one of the example scripts until I come up with something...
Thanks,
- Jason
Directly connecting an LCD to a T7 would likely be a time consuming process and may not be able to be done given the limited size allowances for Lua scripts since it is a scripted language. Interfacing with an Arduino that controls the LCD is definitely a good solution.
I would normally suggest that you look into SPI first because it is a little bit easier to understand than I2C but the Open Source community has a lot of I2C examples out there. Using the I2C protocol may also help structure your code a little bit more because it will force you to maintain a "register" based mind-set. Program the Arduino to give 5-10 different registers that it can display and then have the T7 write to those registers to update them. Feel free to use what ever protocol you want.
There are a few blog posts that you may find interesting. This first post is titled "Arduino I2C Slave Guide" and looks like it covers the topic pretty well.
http://dsscircuits.com/articles/arduino-i2c-slave-guide
The second is titled "Arduino as SPI Slave":
https://forum.arduino.cc/index.php?topic=184527.0
In terms of what we offer, there is one published SPI example for ADXL345 3-Axis accelerometer and two published I2C examples. One for the SRF02 Range Finder and HMC6352 Magnetometer. These examples can be found in the Lua scripting tab and in the examples/Sensor Examples/ drop-down menu to the right of the save button. Both the I2C and SPI protocols as exposed by the LabJack follow a three step approach. Looking for this pattern in the examples will help you understand what they are doing.
1. Configure and load. In this step you need to configure the I2C or SPI bus including the pins, bus speed, relevant operating modes, and the I2C slave address. After configuring you should load the data that you wish to write to the I2C or SPI slave device and for I2C, how much data you expect to read back.
2. Execute I2C/SPI transaction. In this step you need to execute the configured I2C or SPI bus transaction by writing a "1" to the SPI_GO (Register # 5007) or I2C_GO (Register # 5110) register.
3. Verify communication and read data. In this step you should verify that you communicated with the sensor properly, in I2C this means verifying that you received some "ACK" bits. You should also read data from the "RX" data registers. For I2C this is the I2C_DATA_RX register (Register # 5160) and for SPI this is the SPI_DATA_RX register (Register # 5050).
Further reading:
Look at the T7 datasheet pages for more I2C and SPI register descriptions.
I2C Section of the T7's Datasheet
SPI Section of the T7's Datasheet
For I2C we have a simulation tool to help you visualize what is happening on the SCL and SDA lines:
https://labjack.com/support/datasheets/t7/digital-io/i2c/simulation-tool
Thank you very much. That points me in a good direction and I feel now like I can make this work. Probably going to go with I2C, since that seems to make more sense to me.
As a temporary workaround (i.e. cheating :-) I've started playing with DAC and PWM based methods of moving numbers back and forth. The pulse width in extended feature seems to be an easy way of decoding the "analogWrite" function going from arduino to T7, while the DAC to "analogRead" function gets me back from the T7 to the arduino. These are obviously suboptimal methods, but do allow for 8 and 10 bit values to be passed without any real work.
Regards,
- Jason
If you are "only" about to display stuff on an lcd, you might also an i2c-enabled lcd directly from T7's i2c, without an arduino in between.
Like https://www.datsi.fi.upm.es/docencia/Informatica_Industrial/DMC/LCD-Blue... or even with limited keys like https://www.crystalfontz.com/product/cfa533tmikc-alphanumeric-lcd-displa...
Regards
Marcel
Another thought along those lines is to connect a Raspberry Pi to the T7 over USB or Ethernet, and then look at all the options for displays with a Raspberry Pi.