Problem using analog PIN

Hi all,

I'm working on a project regarding P300 waves, and for this reason I need a precise synchronization between the visual stimulation and the EEG signal. In order to achieve this, I'm using a photoresistor placed close to the screen of my laptop, with which I'd like to detect the change in brightness of a square present on my screen. 

The firmware of my OpenBCI 32-bit board is v1. This is what I obtain when I send the initialization command: 

OpenBCI V3 16 channel
ADS1299 Device ID: 0x3E
LIS3DH Device IDE: 0x33
$$$

In the code that I uploaded on the board I declared the following variables:
int analogSensor = A7;
short int sensorValue;

then, changed the following lines in the setup function:
OBCI.useAccel = false; 
OBCI.useAux = true;     

and added these ones in the loop function (inside the if(is_running):
sensorValue = analogRead(analogSensor);
OBCI.auxData[2] = sensorValue;


The problem is that the value of OBCI.auxData[2] doesn't change even if the brightness does, as you can see from the following image: https://postimg.org/image/ysetb8gdd/.

Here are some things that I tried to solve the problem:
  • I built the same circuit with an Arduino, by using the same photoresistor, and everything works well (the signal that I obtain is coherent with the change in brightness);
  • instead of copying sensorValue in OBCI.auxData[2] I tried to copy in it the value of a counter (0-1023) and I could correctly read it;
  • I read the signal of the photoresistor contemporarily with the OpenBCI and with an Arduino, and with the Arduino I could read it correctly, while with the OpenBCI it was not updated.
Does anybody have any idea about how to solve the problem?

Thank you in advance for your help

Davide



Comments

  • wjcroftwjcroft Mount Shasta, CA
    Davide, hi. I assume you've seen the external trigger tutorial,

    http://docs.openbci.com/Tutorials/06-External_Trigger_32bit_Example

    But that's not using analog pin. @yttuncel has a code snippet here using analog, he may chime in,

    http://openbci.com/forum/index.php?p=/discussion/comment/5075/#Comment_5075

  • @wjcroft Thank you for your reply!

    Yes, I've read the external trigger tutorial, but as you say it's a digital pin and not analog pin. 

    It seems to me that the value stored in OpenBCI.auxData the first time the loop is executed then doesn't change.

    @yttuncel is using the same code as mine:

       //Analog Trigger Read
          analogValue = analogRead(A7);
          board.auxData[1] = analogValue;

    and in the .txt file posted the value of the second column in the auxValues is always 0.0..

    Do you think that upgrading the board firmware to v2 will help? 
  • wjcroftwjcroft Mount Shasta, CA
    Let's ask AJ Keller @pushtheworld, the V2 dev.

  • edited January 2017
    You can see an example of an analog sensor with V2 firmware. Please note this requires updating all three uC's if you have V1 firmware!

  • Thanks @pushtheworld, I'll try to update the firmware on all the uC and see if it works!
  • Hi, 
    I uploaded the firmware on all the three microcontrollers. 

    When I use the "defaultBoard" firmware, everything is working fine and I can read and visualize all the data in the correct way, both with OpenBCI_GUI and with the software that I wrote.

    But when I use the code "BoardWithAnalogSensor" this is no longer true: even with the OpenBCI_GUI it is not possible for me to read any data.. I didn't change anything in the code and I don't why this is happening

    Thanks again
  • edited January 2017
    @davide_93 ;I'm glad you were able to read from it!

    Need to update a line in the processing to read the different stop byte. The idea is you are telling the Driver NOT to scale the last 6 bytes. You can see a concrete example in how to properly do this in the node,js repo sample packet properties


    You can check it out and you won't have that problem. There is a build coming for it soon!
  • Thank you @pushtheworld for your reply.

    With the default board firmware I could read only the channels data, I tried to read the analog sensor by disabling the useAccel and writing
    board.auxData[0] = analogRead(A7)
    but it didn't work.

    What I noticed is that the value provided at the first sample is correct, but then it is no longer updated..

    Then I tried to the firmware with the analog sensor, but I didn't work due to the problem that you explained me.

    I really don't know what to do :(




  • Download the OpenBCI_GUI (repo | .zip) and processing 3 and run that gui! I just updated the master copy for you! 
  • edited January 2017
    The processing GUI only really supports the default board, once you start changing the firmware, the assumption is you are writing custom code probably for doing work or analysis on. You should try using the node (you can get streaming in a couple lines), and if you, for example, need to pipe into python, check out the full duplex node to python example. We (@pushtheworld) use the different stop bytes to do wireless time syncing for out new openbci app thinker.

  • thank you very much for your help! With the new version of the OpenBCI GUI I was able to correctly read the data of my analog sensor. 

    I'm writing my custom software with Processing to read the data from the OpenBCI: right now I can correctly read the channels data, but I'm still having problems with the analog sensor, probably because I need to adjust my code to the v2 firmware. 
  • I tried to fix my code, but it is still impossible for me to see the auxValue changing: it has always the same value even though I know that it is changing (and with the OpenBCI GUI I can see it changing in the .txt file). 

    This is the code that I wrote for my Processing application (I know that it is very simple and probably not well-written): now, for sure the problem is related to it, even though I cannot figure out where it is.
    I use as "end Byte" for the data packet the byte 0xC1 as stated in OpenBCI_DataFormat.


Sign In or Register to comment.