{"action":"created","issue":{"url":"https://api.github.com/repos/rwaldron/johnny-five/issues/1155","repository_url":"https://api.github.com/repos/rwaldron/johnny-five","labels_url":"https://api.github.com/repos/rwaldron/johnny-five/issues/1155/labels{/name}","comments_url":"https://api.github.com/repos/rwaldron/johnny-five/issues/1155/comments","events_url":"https://api.github.com/repos/rwaldron/johnny-five/issues/1155/events","html_url":"https://github.com/rwaldron/johnny-five/issues/1155","id":160147563,"number":1155,"title":"L298N not working","user":{"login":"illogica","id":9421912,"avatar_url":"https://avatars.githubusercontent.com/u/9421912?v=3","gravatar_id":"","url":"https://api.github.com/users/illogica","html_url":"https://github.com/illogica","followers_url":"https://api.github.com/users/illogica/followers","following_url":"https://api.github.com/users/illogica/following{/other_user}","gists_url":"https://api.github.com/users/illogica/gists{/gist_id}","starred_url":"https://api.github.com/users/illogica/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/illogica/subscriptions","organizations_url":"https://api.github.com/users/illogica/orgs","repos_url":"https://api.github.com/users/illogica/repos","events_url":"https://api.github.com/users/illogica/events{/privacy}","received_events_url":"https://api.github.com/users/illogica/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2016-06-14T10:27:11Z","updated_at":"2016-08-23T21:17:31Z","closed_at":null,"body":"I built a small robot with two 5V DC motors. I want to drive them using a L298N and an Arduino Nano clone ([this one](https://www.amazon.it/gp/product/B015MGHH6Q/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1)).\r\nI uploaded the StandardFirmata program in the Nano, using Arduino IDE 1.6.9.\r\nI communicate with the Nano using a JY-MCU bluetooth module (working, node is communicating correctly with the module).\r\nI uploaded the following program:\r\n\r\n```\r\nvar five = require(\"johnny-five\"), board, motor1, motor2, led;\r\n\r\nboard = new five.Board();\r\n\r\nboard.on(\"ready\", function() {\r\n  // Create a new `motor` hardware instance.\r\n  motor1 = new five.Motor({\r\n    pins: {\r\n      pwm:3,\r\n\t  dir:4,\r\n\t  cdir: 7\r\n    }\r\n  });\r\n  \r\n  motor2 = new five.Motor({\r\n    pins: {\r\n\t  pwm:5,\r\n\t  dir:8,\r\n\t  cdir: 12\r\n\t}\r\n  });\r\n\t\r\n  motor1.start(124);\r\n  motor2.start(124);\r\n\r\n  board.repl.inject({\r\n    motor1: motor1,\r\n    motor2: motor2\r\n  });\r\n  \r\n  // \"start\" events fire when the motor is started.\r\n  motor1.on(\"start\", function() {\r\n    console.log(\"start motors\", Date.now());\r\n\r\n    // Demonstrate motor stop in 2 seconds\r\n    board.wait(5000, function() {\r\n      motor1.stop();\r\n\t  motor2.stop();\r\n    });\r\n  });\r\n\r\n  // \"stop\" events fire when the motor is stopped.\r\n  motor1.on(\"stop\", function() {\r\n    console.log(\" motors stopped\", Date.now());\r\n\tmotor1.start(200);\r\n  });\r\n});\r\n```\r\nWhen I launch the program, Node is correctly communicating with the Nano and the console prints meaningful messages, but the PWM outputs don't output  thing and even the direction pins act somewhat randomly.\r\nOut of desperation I uploaded this program into the Arduino:\r\n\r\n```\r\n//Code by Reichenstein7 (thejamerson.com), adapted for my application\r\n\r\n//Keyboard Controls:\r\n//\r\n// 1 -Motor 1 Left\r\n// 2 -Motor 1 Stop\r\n// 3 -Motor 1 Right\r\n//\r\n// 4 -Motor 2 Left\r\n// 5 -Motor 2 Stop\r\n// 6 -Motor 2 Right\r\n\r\n// Declare L298N Dual H-Bridge Motor Controller directly since there is not a library to load.\r\n\r\nint SPEED = 255;\r\n\r\n// Motor 1\r\nint dir1PinA = 8;\r\nint dir2PinA = 12;\r\nint speedPinA = 5; // Needs to be a PWM pin to be able to control motor speed\r\n\r\n// Motor 2\r\nint dir1PinB = 7;\r\nint dir2PinB = 4;\r\nint speedPinB = 3; // Needs to be a PWM pin to be able to control motor speed\r\n\r\nvoid setup() {  // Setup runs once per reset\r\n// initialize serial communication @ 9600 baud:\r\nSerial.begin(9600);\r\n\r\n//Define L298N Dual H-Bridge Motor Controller Pins\r\n\r\npinMode(dir1PinA,OUTPUT);\r\npinMode(dir2PinA,OUTPUT);\r\npinMode(speedPinA,OUTPUT);\r\npinMode(dir1PinB,OUTPUT);\r\npinMode(dir2PinB,OUTPUT);\r\npinMode(speedPinB,OUTPUT);\r\n\r\n}\r\n\r\nvoid loop() {\r\n\r\n// Initialize the Serial interface:\r\n\r\nif (Serial.available() > 0) {\r\nint inByte = Serial.read();\r\nint speed; // Local variable\r\n\r\nswitch (inByte) {\r\n\r\n//______________Motor 1______________\r\n\r\ncase '1': // Motor 1 Forward\r\nanalogWrite(speedPinA, SPEED);//Sets speed variable via PWM \r\ndigitalWrite(dir1PinA, LOW);\r\ndigitalWrite(dir2PinA, HIGH);\r\nSerial.println(\"Motor 1 Forward\"); // Prints out “Motor 1 Forward” on the serial monitor\r\nSerial.println(\"   \"); // Creates a blank line printed on the serial monitor\r\nbreak;\r\n\r\ncase '2': // Motor 1 Stop (Freespin)\r\nanalogWrite(speedPinA, 0);\r\ndigitalWrite(dir1PinA, LOW);\r\ndigitalWrite(dir2PinA, HIGH);\r\nSerial.println(\"Motor 1 Stop\");\r\nSerial.println(\"   \");\r\nbreak;\r\n\r\ncase '3': // Motor 1 Reverse\r\nanalogWrite(speedPinA, SPEED);\r\ndigitalWrite(dir1PinA, HIGH);\r\ndigitalWrite(dir2PinA, LOW);\r\nSerial.println(\"Motor 1 Reverse\");\r\nSerial.println(\"   \");\r\nbreak;\r\n\r\n//______________Motor 2______________\r\n\r\ncase '4': // Motor 2 Forward\r\nanalogWrite(speedPinB, SPEED);\r\ndigitalWrite(dir1PinB, LOW);\r\ndigitalWrite(dir2PinB, HIGH);\r\nSerial.println(\"Motor 2 Forward\");\r\nSerial.println(\"   \");\r\nbreak;\r\n\r\ncase '5': // Motor 1 Stop (Freespin)\r\nanalogWrite(speedPinB, 0);\r\ndigitalWrite(dir1PinB, LOW);\r\ndigitalWrite(dir2PinB, HIGH);\r\nSerial.println(\"Motor 2 Stop\");\r\nSerial.println(\"   \");\r\nbreak;\r\n\r\ncase '6': // Motor 2 Reverse\r\nanalogWrite(speedPinB, SPEED);\r\ndigitalWrite(dir1PinB, HIGH);\r\ndigitalWrite(dir2PinB, LOW);\r\nSerial.println(\"Motor 2 Reverse\");\r\nSerial.println(\"   \");\r\nbreak;\r\n\r\ndefault:\r\n// turn all the connections off if an unmapped key is pressed:\r\nfor (int thisPin = 2; thisPin < 11; thisPin++) {\r\ndigitalWrite(thisPin, LOW);\r\n}\r\n}\r\n}\r\n}\r\n```\r\n\r\nThis program works, I can command both motors via the Arduino serial monitor, so the hardware is correctly connected and properly working.\r\n\r\nAm I looking at a FIrmata problem or Johnny-Five problem? \r\n"},"comment":{"url":"https://api.github.com/repos/rwaldron/johnny-five/issues/comments/241881724","html_url":"https://github.com/rwaldron/johnny-five/issues/1155#issuecomment-241881724","issue_url":"https://api.github.com/repos/rwaldron/johnny-five/issues/1155","id":241881724,"user":{"login":"rwaldron","id":27985,"avatar_url":"https://avatars.githubusercontent.com/u/27985?v=3","gravatar_id":"","url":"https://api.github.com/users/rwaldron","html_url":"https://github.com/rwaldron","followers_url":"https://api.github.com/users/rwaldron/followers","following_url":"https://api.github.com/users/rwaldron/following{/other_user}","gists_url":"https://api.github.com/users/rwaldron/gists{/gist_id}","starred_url":"https://api.github.com/users/rwaldron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rwaldron/subscriptions","organizations_url":"https://api.github.com/users/rwaldron/orgs","repos_url":"https://api.github.com/users/rwaldron/repos","events_url":"https://api.github.com/users/rwaldron/events{/privacy}","received_events_url":"https://api.github.com/users/rwaldron/received_events","type":"User","site_admin":false},"created_at":"2016-08-23T21:17:31Z","updated_at":"2016-08-23T21:17:31Z","body":"> I built a small robot with two 5V DC motors. I want to drive them using a L298N and an Arduino > Nano clone (this one).\r\n> I uploaded the StandardFirmata program in the Nano, using Arduino IDE 1.6.9.\r\n> I communicate with the Nano using a JY-MCU bluetooth module (working, node is communicating correctly with the module).\r\n\r\n\r\n- What is your power source on the Nano side?\r\n- How are you powering the motors?\r\n"}}
{"actor":{"display_login":"rwaldron"}}