title: Raspberry Pi Python GT-511C3 programming error
body: <p><strong>[SOLVED]</strong>
  Solution in the updates below</p>
  
  <p>I tried looking for the solution, and I have no idea where to ask at this point. If anyone could help me with the following.</p>
  
  <p>I am connecting Raspberry Pi Zero to the <a href="http://www.robotshop.com/media/files/pdf/datasheet-sen-11792.pdf" rel="nofollow">GT-511C3 fingerprint scanner</a>, and after getting it to respond, I constantly receive the same error code. I am not sure if problem is in my code or is in the device, and at this point I am not sure how to debug.</p>
  
  <p>Here is what I do:</p>
  
  <pre><code>import wiringpi as wp
  from struct import *
  
  signal = pack('&lt;BBHIH', 0x55, 0xAA, 0x01, 0x00, 0x03)
  chk = sum(map(ord, list(signal)))
  chk = map(chr, [chk % 256, chk / 256])
  signal += chk[0] + chk[1]
  
  wp.wiringPiSetup()
  serial = wp.serialOpen('/dev/ttyAMA0', 9600)
  wp.serialPuts(serial, signal)
  
  res = []
  while True:
      ack = wp.serialGetchar(serial)
      if ack == -0x01:
          break
      res.append(ack)
  print res
  </code></pre>
  
  <p>I am getting a response:
  <code>['0x55', '0xaa', '0x01', '0x00', '0x0f', '0x10', '0x00', '0x00', '0x31', '0x00', '0x50', '0x01']</code>. The structure breakdown is described on page 6 of the <a href="http://www.robotshop.com/media/files/pdf/datasheet-sen-11792.pdf" rel="nofollow">User's Manual</a>, but in a nutshell it's a <code>NACK</code> response with <code>DEV_ERROR</code> comment. I am not sure what could be going wrong here.</p>
  
  <p>Any ideas?</p>
  
  <p><strong>UPDATE 1:</strong></p>
  
  <p>I got the board to work on Arduino Uno, but R-Pi still has the same problem as before - receiving <code>NACK_DEV_ERR</code> all the time. I think we can safely say the problem is in the R-Pi or in my code. Will update...</p>
  
  <p><strong>UPDATE 2:</strong></p>
  
  <p>I think the problem was the combination of little and big endianness in the <code>path</code> routine - some of the bytes were swapped (including the checksum). I am not sure why incorrect checksum and/or command code returns <code>NACK_DEV_ERR</code>. WIll look into it more.</p>
  
  <p><strong>UPDATE 3:</strong></p>
  
  <p>The problem is definitely the command sequence. Apparently, wrong checksum, wrong command, wrong parameter can return <code>NACK_DEV_ERR</code> - not sure why there are no specific errors for that. Also, noticed a lot of other inconsistencies in the error codes.</p>
  
  <p>If anyone interested, the working code is on <a href="https://github.com/zafartahirov/fingerpi" rel="nofollow">GitHub</a>.</p>