Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ttl channel outputs in State Machine r2
#1
To whom it may concern,

I am pretty new to Bpod (and Matlab) and looking for some advise as to how to drive different components using the State Machine r2. 

Up to now, we have been performing experiments using the previous version State Machine r1 and used the bare wires or ttl ports to directly drive the different components of the setup (e.g. stimulus apparatus, several speakers, triggers for scanimage software  and shatter). These were physically accessible from the bpod arduino board and could be directly coded into the state matrix. We have recently purchased the new Bpod machine r2 and I would like to know what's the best way to go in order to drive several components while having only 2 ttl input/output. Also how much coding would this require? it would be great to have a sample code just to have an idea. Thanks. Dani
Reply
#2
Hi Dani,


To add additional digital I/O lines, you can add DIO modules each consisting of: 
1 Teensy 3.2 with female headers soldered in, and DIO firmware loaded
1 Teensy Shield

Each Teensy you add (up to 5 total) will give the state machine control of 6 digital output channels and 6 digital input channels.
See comments in the DIO firmware file (link above) for usage instructions

I hope this helps,
-Josh
Reply
#3
(02-16-2019, 08:01 AM)Dani Wrote: Thanks Josh, your instructions were really helpful! 
Reply
#4
(02-16-2019, 08:01 AM)Josh Wrote: Hi Dani,


To add additional digital I/O lines, you can add DIO modules each consisting of: 
1 Teensy 3.2 with female headers soldered in, and DIO firmware loaded
1 Teensy Shield

Each Teensy you add (up to 5 total) will give the state machine control of 6 digital output channels and 6 digital input channels.
See comments in the DIO firmware file (link above) for usage instructions

I hope this helps,
-Josh
Hi Josh,

We have the same problem in our lab, and we got Bpod analog input module and output module which are currently not in use. Can I use them as Bpod state machine DIO devices?

Cheers,

Kun
Reply
#5
Hi Kun,

I'm assuming you've used all of the input and LED channels on the port interface boards (normally for nosepokes and LEDs, but unused channels can work as digital GPIO)

You can set the analog input module to detect incoming 3.3 or 5V pulses using its MATLAB class.
The code to set up a channel (for instance, channel 2) is roughly:

Code:
myChannel = 2;
A = BpodAnalogIn('COM3');
A.Thresholds(myChannel) = 2.5;
A.ResetVoltages(myChannel) = 1;
A.SMeventsEnabled(myChannel) = 1;
A.startReportingEvents();

This will return AnalogIn1_2 events each time the line goes from low to high. Unlike the BNC and port input channels, you won't get events when the line goes from high -> low. Also keep in mind that the input channel is not optically isolated, so make sure the input voltage is something reasonable (-10 to +10VDC).

For output, you'd use the WavePlayer class to play 5V pulses on trigger.

I hope this helps!
-Josh
Reply
#6
(02-16-2019, 08:01 AM)Josh Wrote: Hi Dani,


To add additional digital I/O lines, you can add DIO modules each consisting of: 
1 Teensy 3.2 with female headers soldered in, and DIO firmware loaded
1 Teensy Shield

Each Teensy you add (up to 5 total) will give the state machine control of 6 digital output channels and 6 digital input channels.
See comments in the DIO firmware file (link above) for usage instructions

I hope this helps,
-Josh


Hi Josh,   

I'd like to do something similar, but I was not totally clear on the instructions in the firmware file.  For example, if I want to send a TTL out in a particular state, what is the syntax for the "OutputAction" to write to one of the Channels 19-23 on the Teensy?  'OutputActions', {'Port1Out', [19 1]})?  Do I have to edit AddState.m too?  

Many thanks, 

Emily
Reply
#7
Hi Emily,

Port1Out is an event, not the name of an output action. If you click on the magnifying glass icon from the Bpod console, in the right-most column you'll see a list of the valid output actions. 'DIO1' should be there if you have the DIO example firmware loaded onto a Teensy 3.2 with the Bpod Teensy Shield.

{'DIO1', [19 1]} sets Teensy pin 19 to HIGH.
{'DIO1', [19 0]} sets Teensy pin 19 to LOW.

And so forth for pins 19-23.

Teensy pins 2-7 are configured as digital inputs, and generate DIO1_CH_Hi and DIO1_CH_Low events, where CH is channel 2-7, when they read incoming high and low TTL levels.

I hope this helps!

-Josh
Reply
#8
(07-23-2020, 10:13 PM)Josh Wrote: Hi Emily,

Port1Out is an event, not the name of an output action. If you click on the magnifying glass icon from the Bpod console, in the right-most column you'll see a list of the valid output actions. 'DIO1' should be there if you have the DIO example firmware loaded onto a Teensy 3.2 with the Bpod Teensy Shield.

{'DIO1', [19 1]} sets Teensy pin 19 to HIGH.
{'DIO1', [19 0]} sets Teensy pin 19 to LOW.

And so forth for pins 19-23.

Teensy pins 2-7 are configured as digital inputs, and generate DIO1_CH_Hi and DIO1_CH_Low events, where CH is channel 2-7, when they read incoming high and low TTL levels.

I hope this helps!

-Josh

Thanks, Josh! 

Very helpful!  I've been able to implement it, but I'm having a hard time setting some of the pins to LOW.  {'DIO1', [19 0]}  works, but the using {'DIO1', [XX 0]}  on pins 20-23 doesn't work.  I can switch 20-23 to high but not back to low (confirmed on an oscilloscope).  Is there something different about these pins? 

Cheers, 
 Emily
Reply


Forum Jump: