Exercises | Chapter3 | PTFL-Book

Exercise 1 (page 30):

Read the PFTL DAQ manual and find a way to set an analog output to 1 Volt.

I read the manual and the following issues occurred:

  • First, it should be specified that it is channel „A0“ that is read from.

  • I personally find the explanation of the manual confusing. „It takes one argument, CH:{} (…) Example IN:CH5“ So, „:{}“ is the space holder for „5“??? I think it is somehow linked to pythons string formatting syntax. Nevertheless, I find this very confusing for beginners. Especially because this first experiment should reveal how easy it is to deal with python and microcontrollers in experiments. So instructions should be straight and simple.

  • „Takes one argument (… ) between 0 and 9“

    • Why only 10 options, if the DUE has 12 ANALOG IN?
  • The manual says: „OUT:: Command for setting the output of an analog channel. It takes as arguments the channel CH:{} and the value, {<4}. The value has to be in the range 0 − 4095, while the channel has to be either 0 or 1. Returns: the value that the device received Example: OUT:CH0:1024><4}. The value has to be in the range 0 − 4095, while the channel has to be either 0 or 1. Returns: the value that the device received“

    • Sorry, but I really don’t understand this sentence. First the value has to be smaller than 4 and than it can be in the range between 0-4095???
  • We are expected to set analog output to 1 Volt. But only the bit-depth (2^12 -1) = 4095 is given. But this is only explained in 3.6.1. I think this information needs to be provided beforehand, or a short lookup table presented.

Exercise 2 (page 30):

Now that you have set up the experiment, you know how to set and read values. Acquire the I-V curve of the diode. It’s a challenging exercise, aimed at showing you that it doesn’t take a long time to be able to achieve an essential goal.

  • The way the diode is inserted in the breadboard (polarity) should be explained for future readers.
  • I tried to get the data in a for-loop like this:
data = []
for output_value in range(0,4095, 400):
    message = 'OUT:CH0:' + str(output_value) +'\n'
    value = device.readline()

and get this as output when data is printed:

[b'Command not known\n',
 b'Command not known\n',
 b'IN:CH0Command not known\n',
 b'Command not known\n',
 b'Command not known\n',
 b'Command not known\n',
 b'Command not known\n',
 b'Command not known\n',
 b'Command not known\n',
 b'Command not known\n']

Does someone know what I’m doing wrong? Or could at least write her/his answer to the exercise? Thanks in advance!

By the way, the diode is also suppposed to de- or increase its light emmision, no?

1 Like

First, thanks for the comments. I’ll keep them in mind for updating the book in the coming months. Regarding the syntax for the commands (i.e. using something like {<4} ) I took it from the manual of a standard device (I am almost sure it was a Tektronix) and it ended up being slightly cryptic to give it more realism. Indeed, I can definitely explain it better.

Keeping the channels between 0 and 9 was only a historical reason (it made the syntax easier since it is only 1 digit) but indeed it is not per-se a limitation of the DUE. I’ll also keep it in mind to try to use the full capacities of the DUE later on.

Indeed, this is something that happens all the time in the face to face workshops and normally triggers a nice discussion (there’s always at least one person who knows what a diode is). But indeed I should also add it to the book.

Regarding your solution to the exercise, at first glance I do not see a problem, so the only thing I can think of is that the problem is a previous command that misses the ‘\n’, and therefore the follow up commands are intertwined. Could you check whether an IDN\n command gives you the proper result? Also, note that when you write to the device, it always gives a value back. So, in these lines:


You’ll have to add an extra readline in between.

Also, would it be possible to see all the code you are using? I have the impression there may be a sleep missing that can be a game changer to make it all work.