Erratic behaviour #1

Closed
ardumont opened this Issue Jun 3, 2012 · 10 comments

Projects

None yet

3 participants

@ardumont
Contributor
ardumont commented Jun 3, 2012

Hi Nakkaya,

Thanks for clodiuno!

I'm beginning my journey with arduino (uno) and i try to use clodiuno for that.

Here's my project.clj :

(defproject arduino-lab "1.0.0-SNAPSHOT"
  :description "Mess around with arduino from the comfort of the repl"
  :dependencies [[org.clojure/clojure "1.3.0"]
                 [clodiuno "0.0.3-SNAPSHOT"]
                 [serial-port "1.1.2"]]
  :native-dependencies [[org.clojars.samaaron/rxtx "2.2.0.1"]]
  :dev-dependencies [[native-deps "1.0.5"]]
  :jvm-opts ["-Djava.library.path=./native/linux/x86/"
             "-d32"])

Ii already got over the jar problems... i'm on ubuntu GNU/Linux and on the naming convention, RXTXcomm.jar look only for devices with /dev/ttySxx and on my machine it's /dev/ttyACM0.

But, i got stuck at the very beginning just after that:

arduino-lab.sos> (def bd (arduino :firmata "/dev/ttyS42"))
arduino-lab.sos> bd
#<Ref@11cac41: {:digital-in {2 (0 0 0 0 0 0 0 0), 1 (0 0 0 0 0 0 0 0), 0 (0 0 0 0 0 0 0 0)}, :version [2 2], :port #<RXTXPort /dev/ttyS42>, :interface :firmata}>

As you can see, the :digital-out key is not populated.

This causes a NullPointerException on the call of digital-write call here - https://github.com/nakkaya/clodiuno/blob/master/src/clodiuno/firmata.clj#L95

When i look at the code that's in charge of populated it - on the arduino multi-method in the firmata namespace - https://github.com/nakkaya/clodiuno/blob/master/src/clodiuno/firmata.clj#L147.

  (dotimes [i (count (keys (:digital-in @conn)))]
    (assoc-in! conn [:digital-out i] (repeat 8 0))))

If i wrap this into a function (change directly into the jar and restarting the clojure-jack-in process), the digital-out is then populated:

arduino-lab.sos> (def bd (arduino :firmata "/dev/ttyS42"))
arduino-lab.sos> bd
#<Ref@152c19d: {:digital-out {2 (0 0 0 0 0 0 0 0), 1 (0 0 0 0 0 0 0 0), 0 (0 0 0 0 0 0 0 0)}, :digital-in {2 (0 0 0 0 0 0 0 0), 1 (0 0 0 0 0 0 0 0), 0 (0 0 0 0 0 0 0 0)}, :version [2 2], :port #<RXTXPort /dev/ttyS42>, :interface :firmata}>

And now i can play :D and it is working fine.

Do you have any idea as of why such a behaviour ?

Anyway, can i make you a pull request for this (the wrapping into a private function) ?

@nakkaya
Owner
nakkaya commented Jun 4, 2012

I've merged your pull request.

No idea about the dotimes behaviour, I'll look into it.

@nakkaya nakkaya closed this Jun 4, 2012
@Gonzih
Contributor
Gonzih commented Jun 4, 2012

Doesn't fix issue for me. :( As I can see :digital-in in conn is nil for me.

(ns clojure-arduino.core
  (:use :reload-all clodiuno.core)
  (:use :reload-all clodiuno.firmata))

(System/setProperty "gnu.io.rxtx.SerialPorts" "/dev/ttyACM0")

(defn -main []
  (let [board (arduino :firmata "/dev/ttyACM0")]
    (println @board)
    (Thread/sleep 5000)
    (pin-mode board 12 OUTPUT)
    (digital-write board 12 HIGH)
    (close board)))

{:version [2 3], :port #<RXTXPort /dev/ttyACM0>, :interface :firmata}
Exception in thread "main" java.lang.NullPointerException (NO_SOURCE_FILE:1)
        at clojure.lang.Compiler.eval(Compiler.java:5440)
        at clojure.lang.Compiler.eval(Compiler.java:5415)
        at clojure.lang.Compiler.eval(Compiler.java:5391)
        at clojure.core$eval.invoke(core.clj:2382)
        at clojure.main$eval_opt.invoke(main.clj:235)
        at clojure.main$initialize.invoke(main.clj:254)
        at clojure.main$null_opt.invoke(main.clj:279)
        at clojure.main$main.doInvoke(main.clj:354)
        at clojure.lang.RestFn.invoke(RestFn.java:422)
        at clojure.lang.Var.invoke(Var.java:369)
        at clojure.lang.AFn.applyToHelper(AFn.java:165)
        at clojure.lang.Var.applyTo(Var.java:482)
        at clojure.main.main(main.java:37)
Caused by: java.lang.NullPointerException
        at clodiuno.firmata$eval54$fn__55.invoke(firmata.clj:95)
        at clojure.lang.MultiFn.invoke(MultiFn.java:171)
        at clojure_arduino.core$_main.invoke(core.clj:12)
        at clojure.lang.Var.invoke(Var.java:361)
        at user$eval112.invoke(NO_SOURCE_FILE:1)
        at clojure.lang.Compiler.eval(Compiler.java:5424)
        ... 12 more
@nakkaya
Owner
nakkaya commented Jun 4, 2012

Should be fixed now. I've manually populated digital in/out ports. Tested on Mega.

@ardumont
Contributor
ardumont commented Jun 4, 2012

Hi,

ahhh, i think your problem is elsewhere. I did struggle with this the all week end.

What's your linux distribution ?

On Ubuntu the devices is not seen by the underlying api clodiuno uses RXTXcomm.jar - i opened a pull request to notify @samaaron about this on his api https://github.com/samaaron/serial-port (which does some of the stuff clodiuno does) - https://github.com/samaaron/serial-port/pull/4/files

You must link your device with a name that starts with /dev/ttySxx something else it is not seen.

For me, i did this:

ln -s /dev/ttyACM0 /dev/ttyS42

Hope this helps.

@nakkaya
Owner
nakkaya commented Jun 4, 2012

You can work around that by adding,

(System/setProperty "gnu.io.rxtx.SerialPorts" "/dev/ttyACM0")

I've tested it on an Ubuntu 12 with a Mega 2560 which also registers as /dev/ttyACM0.

@ardumont
Contributor
ardumont commented Jun 4, 2012

Thanks, did not know that :D
I will try your fix now.

Thanks again

@ardumont
Contributor
ardumont commented Jun 4, 2012

All is working for me - even the tips!

@Gonzih
Contributor
Gonzih commented Jun 4, 2012

@nakkaya can you push changes to clojars?

Thanks

@nakkaya
Owner
nakkaya commented Jun 4, 2012

Pushed.

Best,

Nurullah Akkaya
http://nakkaya.com

On Mon, Jun 4, 2012 at 2:06 PM, Max Gonzih
reply@reply.github.com
wrote:

@nakkaya can you push changes to clojars?

Thanks


Reply to this email directly or view it on GitHub:
#1 (comment)

@ardumont
Contributor
ardumont commented Jun 4, 2012

Thanks.

2012/6/4 Nurullah Akkaya <
reply@reply.github.com

Pushed.

Best,

Nurullah Akkaya
http://nakkaya.com

On Mon, Jun 4, 2012 at 2:06 PM, Max Gonzih
reply@reply.github.com
wrote:

@nakkaya can you push changes to clojars?

Thanks


Reply to this email directly or view it on GitHub:
#1 (comment)


Reply to this email directly or view it on GitHub:
#1 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment