0

I'm trying to connect paj7620 to nodemcu micro-controller. I have implemented the following code and it worked perfect on arduino uno. The problem is that I was made to migrate to nodemcu.

Here is my code:

/*
 * Copyright (c) 2015 seeed technology inc.
 * Website    : www.seeed.cc
 * Author     : Wuruibin
 * Modified Time: June 2015
 * Description: This demo can recognize 15 gestures and output the result. 
 *              You can adjust the reaction time according to the actual circumstance
 *              by modifying "#define GES_REACTION_TIME  500".
 * 
 * The MIT License (MIT)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
#include <ESP8266WiFi.h>
#include <Wire.h>
#include "paj7620.h"

/* 
Notice: When you want to recognize the Forward/Backward gesture or other continuous gestures, your gestures' reaction time must less than GES_REACTION_TIME(0.8s). 
        You also can adjust the reaction time according to the actual circumstance.
*/
#define GES_REACTION_TIME       800
#define GES_QUIT_TIME           1000

void setup()
{
    uint8_t error = 0;

    Serial.begin(9600);
    Serial.println("\nPAJ7620U2 TEST DEMO: Recognize 15 gestures.");

    error = paj7620Init();          // initialize Paj7620 registers
    if (error) 
    {
        Serial.print("INIT ERROR,CODE:");
        Serial.println(error);
    }
    else
    {
        Serial.println("INIT OK");
    }
    Serial.println("Please input your gestures:");
    Serial.begin(115200);
  Serial.println();

  // Serial.print("Setting soft-AP configuration ... ");
  // Serial.println(WiFi.softAPConfig(local_IP, gateway, subnet) ? "Ready" : "Failed!");

  Serial.print("Setting soft-AP ... ");
  Serial.println(WiFi.softAP("NODEMCU") ? "Ready" : "Failed!");

  Serial.print("Soft-AP IP address = ");
  Serial.println(WiFi.softAPIP());
}

void loop()
{
    uint8_t data = 0, data1 = 0, error; 

    error = paj7620ReadReg(0x43, 1, &data);             // Read Bank_0_Reg_0x43/0x44 for gesture result.
    if (!error) 
    {
        switch (data)                                   // When different gestures be detected, the variable 'data' will be set to different values by paj7620ReadReg(0x43, 1, &data).
        {
            case GES_RIGHT_FLAG:
                delay(GES_REACTION_TIME);
                paj7620ReadReg(0x43, 1, &data);
                if(data == GES_LEFT_FLAG) 
                {
                    Serial.println("Right-Left");
                }
                else if(data == GES_FORWARD_FLAG) 
                {
                    Serial.println("Forward");
                    delay(GES_QUIT_TIME);
                }
                else if(data == GES_BACKWARD_FLAG) 
                {
                    Serial.println("Backward");
                    delay(GES_QUIT_TIME);
                }
                else
                {
                    Serial.println("Right");
                }          
                break;
            case GES_LEFT_FLAG:
                delay(GES_REACTION_TIME);
                paj7620ReadReg(0x43, 1, &data);
                if(data == GES_RIGHT_FLAG) 
                {
                    Serial.println("Left-Right");
                }
                else if(data == GES_FORWARD_FLAG) 
                {
                    Serial.println("Forward");
                    delay(GES_QUIT_TIME);
                }
                else if(data == GES_BACKWARD_FLAG) 
                {
                    Serial.println("Backward");
                    delay(GES_QUIT_TIME);
                }
                else
                {
                    Serial.println("Left");
                }          
                break;
                break;
            case GES_UP_FLAG:
                delay(GES_REACTION_TIME);
                paj7620ReadReg(0x43, 1, &data);
                if(data == GES_DOWN_FLAG) 
                {
                    Serial.println("Up-Down");
                }
                else if(data == GES_FORWARD_FLAG) 
                {
                    Serial.println("Forward");
                    delay(GES_QUIT_TIME);
                }
                else if(data == GES_BACKWARD_FLAG) 
                {
                    Serial.println("Backward");
                    delay(GES_QUIT_TIME);
                }
                else
                {
                    Serial.println("Up");
                }
                break;
            case GES_DOWN_FLAG:
                delay(GES_REACTION_TIME);
                paj7620ReadReg(0x43, 1, &data);
                if(data == GES_UP_FLAG) 
                {
                    Serial.println("Down-Up");
                }
                else if(data == GES_FORWARD_FLAG) 
                {
                    Serial.println("Forward");
                    delay(GES_QUIT_TIME);
                }
                else if(data == GES_BACKWARD_FLAG) 
                {
                    Serial.println("Backward");
                    delay(GES_QUIT_TIME);
                }
                else
                {
                    Serial.println("Down");
                }
                break;
            case GES_FORWARD_FLAG:
                delay(GES_REACTION_TIME);
                paj7620ReadReg(0x43, 1, &data);
                if(data == GES_BACKWARD_FLAG) 
                {
                    Serial.println("Forward-Backward");
                    delay(GES_QUIT_TIME);
                }
                else
                {
                    Serial.println("Forward");
                    delay(GES_QUIT_TIME);
                }
                break;
            case GES_BACKWARD_FLAG:       
                delay(GES_REACTION_TIME);
                paj7620ReadReg(0x43, 1, &data);
                if(data == GES_FORWARD_FLAG) 
                {
                    Serial.println("Backward-Forward");
                    delay(GES_QUIT_TIME);
                }
                else
                {
                    Serial.println("Backward");
                    delay(GES_QUIT_TIME);
                }
                break;
            case GES_CLOCKWISE_FLAG:
                Serial.println("Clockwise");
                break;
            case GES_COUNT_CLOCKWISE_FLAG:
                Serial.println("anti-clockwise");
                break;  
            default:
                paj7620ReadReg(0x44, 1, &data1);
                if (data1 == GES_WAVE_FLAG) 
                {
                    Serial.println("wave");
                }
                break;
        }
    }
    delay(100);
}
------------------------
|paj7620    | nodemcu  |
------------------------
| VCC       | 3.3v     |
------------------------
| GND       | GND      |
------------------------
| SCL       | D1       |
------------------------
| SDA       | D2       |
------------------------

After connecting the ports like the above table, I get the following error when I am trying to upload the code on nodemcu.

Would someone help me how to resolve this error?

enter image description here

Wiring enter image description here

PS I have also tried I2C Scanner as @timemage mentioned in comments.

enter image description here

PS 2 It works properly when I connect the paj7620 to arduino compiling the above code.

enter image description here

output: enter image description here

13
  • Do you have external pull-up resistors on the I2C bus? What else, if anything, do you have connected to the board? – timemage Feb 8 at 15:21
  • @timemage Sorry I am newbie in this field. can't understand what you have said. would you please give me more details? – Mostafa Ghadimi Feb 8 at 15:28
  • If you haven't already, run the I2C scanner and make sure your sensor is showing up in it. – timemage Feb 8 at 15:31
  • @timemage I got the following error: ``` /packages/esp8266/hardware/esp8266/2.7.4/tools/esptool/esptool.py", line 672, in flash_defl_block self.ESP_FLASH_DEFL_DATA, struct.pack('<IIII', len(data), seq, 0, 0) + data, self.checksum(data), timeout=timeout) check_command raise FatalError("Failed to %s. Only got %d byte status response." % (op_description, len(data))) esptool.FatalError: Failed to write compressed data to flash after seq 12. Only got 1 byte status response. esptool.FatalError: Failed to write compressed data to flash after seq 12. Only got 1 byte status response. ``` – Mostafa Ghadimi Feb 8 at 16:19
  • 1
    You need to close the serial monitor before uploading a new sketch, that looks like an upload error. – Maximilian Gerhardt Feb 8 at 17:05
1

Special thanks to @timemage for his support. After struggling with the board for more than 6 hours it works properly. I will describe and give more details about how the problem was solved later on.

Arduino Uno has 5 Analog inputs, while there isn't any of them on nodemcu. To connect paj7620 to nodemcu, it is noticable that as @timemage said:

"The A4 and A5 on the UNO are where the ATMega328P's I2C bus signals happen to be. Earlier versions of the Arduino UNO and related boards didn't have dedicated SDA and SCL headers as they do now. On those UNO that have SDA and SCL pins on the upper digital header, they are the same exact signal as those found on A4 and A5."

So the first schema was correct.

As it is implied from the fifth page of this link there isn't any difference among 3.3v inputs on nodemcu. But I have changed wiring like the following image and it works!

enter image description here

#COLOR MAPPING
RED: VCC - 3.3v
BLACK: GND
ORANGE: SCL - D1
GREEN: SDA - D2

I hope it helps, cause there isn't any way to trace the problem. :)

1
  • 1
    When you get a chance, try the load test on your "bad" 3.3v pin. Just put something on the order of 50 ohms there. It should draw about 66 mA and pin should stay near 3.3v If the voltage drops off to nothing, maybe mark the pin somehow so you don't try to use it in the future. And you know, fix the soldering when you can. =) – timemage Feb 8 at 21:30
0

You've gotten rather quiet over there since I suggested zooming in on your sensor board. Just so this question doesn't circulate around in the system for years, here's an answer:

Zooming in on poorly soldered header.

Your soldering should closer to this. Hopefully better, as these are ones I did:

Soldering

The solder short of sort web-up the sides of the pins. The use the term "fillet" for that. Where your pads around the through-hole looks broader than the ones that are on the board above, it should probably look a bit better. There shouldn't be unfilled parts of the through-hole, in any case. At least not on the side you're soldering.

I expect it will at least show in the I2C scanner when you fix that. It may show a different address from what is default in the library, in which case you may need to tell it to use the address that shows in the scanner.

8
  • 2
    you are right, but it works properly when I run the above code on arduino. The problem is with connection to nodemcu. – Mostafa Ghadimi Feb 8 at 19:28
  • The connection may be so weak that it doesn't take much to affect whether or not it "works". – timemage Feb 8 at 19:31
  • 1
    I have connected it to the arduino like this picture. scl to a5 and sda to a4. How can I change the above code that works the same? I think the problem is with the connection of pins to paj and nodemcu. But I didn't find any resource about connecting paj to nodemcu and I have added my code to see whether it has solution or not. – Mostafa Ghadimi Feb 8 at 19:42
  • I don't believe there's anything wrong with the I2C scanner running on the esp8266. And I don't believe that it's worth dealing with your original code until it shows in the scanner. As I said, I'm sure the problem is something more fundamental. – timemage Feb 8 at 19:45
  • 1
    I don't know where the problem is. I have edited the post again. would you please take a look at that? – Mostafa Ghadimi Feb 8 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.